@klever/sdk-web v1.5.0
Kleverchain SDK library
The SDK module provides a quick and easy interface to make contract calls to the blockchain via the Klever wallet's injected methods.
For a more detailed and organized documentation, please visit the official Kleverchain SDK Documentation website.
Installation
$ npm install @klever/sdk-webor
$ yarn add @klever/sdk-webBasic usage
import { web, ITransfer, TransactionType } from "@klever/sdk-web";
const payload: ITransfer = {
amount: 100 * 10 ** 6,
receiver: "receiverAddress",
kda: "KLV",
};
await web.initialize();
const unsignedTx = await web.buildTransaction([
{
payload,
type: TransactionType.Transfer,
},
]);
const signedTx = await web.signTransaction(unsignedTx);
const response = await web.broadcastTransactions([signedTx]);Execute Code On Account Change
To execute code when the user changes their account, you can use the onAccountChange method. This method accepts a callback function that will be executed whenever the account changes.
import { web } from '@klever/sdk-web';
...
function accountChangeCallback((accountChangeEvent) {
if (
web.isKleverAccount(accountChangeEvent.address, accountChangeEvent.chain)
) {
console.log('Account changed:', accountChangeEvent.address);
// You can perform any action here, such as updating the UI or fetching new data.
} else {
console.error('Not a Klever Account: ', accountChangeEvent.address);
}
});
web.initialize({
accountChangeCallback
})
...Changing Network
The default network is the Kleverchain Mainnet, but if you want to use the Kleverchain Testnet or a local version of the Kleverchain, you can change the kleverWeb provider object by setting it before calling the initialize function.
import { web, IProvider } from '@klever/sdk-web';
...
const provider:IProvider = {
api: 'https://api.testnet.klever.org',
node: 'https://node.testnet.klever.org'
};
window.kleverWeb.provider = provider;
web.initialize();
...Transactions
All available transactions:
TransferFreezeUnfreezeDelegateUndelegateClaimWithdrawCreateAssetAssetTriggerConfigITOCreateMarketplaceConfigMarketplaceSellBuyCancelMarketOrderProposalVoteCreateValidatorConfigValidatorUnjailSetAccountNameUpdateAccountPermission
6 months ago
8 months ago
5 months ago
9 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago