Note: KardiaChain is now fully compatible with standard web3 client libraries. Developers are recommended to use the standard web3 libraries in previous page instead of this.
importKardiaClient from 'kardia-js-sdk';const RPC_ENDPOINT ='YOUR_RPC_ENDPOINT';const kardiaClient =newKardiaClient({ endpoint: RPC_ENDPOINT });// Account moduleconst accountModule =kardiaClient.account;// Get balanceconst balance = await accountModule.getBalance('YOUR_WALLET_ADDRESS');
Access wallet by private key
import{KardiaAccount} from 'kardia-js-sdk';const wallet =KardiaAccount.getWalletFromPK('YOUR_ADDRESS_PRIVATE_KEY');// Expected result:// {// address: "YOUR_WALLET_ADDRESS",// privateKey: "YOUR_ADDRESS_PRIVATE_KEY",// balace: 123 // your wallet balance// }
Access wallet by seed phrase
import{KardiaAccount} from 'kardia-js-sdk';const wallet =KardiaAccount.getWalletFromMnemonic('YOUR_MNEMONIC_PHRASE');// Expected result:// {// address: "YOUR_WALLET_ADDRESS",// privateKey: "YOUR_ADDRESS_PRIVATE_KEY",// balace: 123 // your wallet balance// }
KAI Module
Event Handler
const topic =keccak256('Transfer(address,address,uint256)');const filterId = await kardiaClient.kaiChain.newFilter({ fromBlock:200000, topics: [topic] })// To get all logsconst allLogs = await kardiaClient.kaiChain.getFilterLogs(filterId);// To get logs since last pollconst logs = await kardiaClient.kaiChain.getFilterChanges(filterId);
KRC20 Module
Get KRC20 balance of a wallet
importKardiaClient from 'kardia-js-sdk';const RPC_ENDPOINT ='YOUR_RPC_ENDPOINT';const kardiaClient =newKardiaClient({ endpoint: RPC_ENDPOINT });const krc20Instance =kardiaClient.krc20;// Fetch KRC20 token's data from smart contractawait krc20Instance.getFromAddress('KRC20_TOKEN_ADDRESS');const balance = await krc20Instance.balanceOf('YOUR_WALLET_ADDRESS');// `balance` will be your wallet's balance, but with token's `decimals` padding.// To get real ballance, use the following codeconst decimals =krc20Instance.getDecimals();const parsedBalance = balance /10** decimals;
Send a KRC20 transaction
importKardiaClient from 'kardia-js-sdk';const RPC_ENDPOINT ='YOUR_RPC_ENDPOINT';const kardiaClient =newKardiaClient({ endpoint: RPC_ENDPOINT });const krc20Instance =kardiaClient.krc20;const txResult = await krc20Instance.transfer('YOUR_WALLET_PRIVATE_KEY','RECEIVER_ADDRESS',1// Amount of tokens to send);
Transaction Module
Creating a transaction
importKardiaClient from 'kardia-js-sdk';const RPC_ENDPOINT ='YOUR_RPC_ENDPOINT';const kardiaClient =newKardiaClient({ endpoint: RPC_ENDPOINT });// Get your wallet's latest nonceconst nonce = await kardiaClient.account.getNonce('YOUR_WALLET_ADDRESS');const txData = { to:'RECEIVER_WALLET_ADDRESS', nonce, gas:3000000,// Gas limit gasPrice:1*10**9,// Minimum Gas Price = 1 OXY value:231095,// Amount of KAI to send};// Send transaction to network and get transaction hash immediatelyconst txHash = await kardiaClient.transaction.sendTransaction( txData,'YOUR_WALLET_PRIVATEKEY');// txHash should be something like '0x0a2db5831c314363a97a79f416061a9daec5230f8b6306cd1c431b467c42f820'// If you want to wait to the transaction to complete, follow the below codeconst txResult = await kardiaClient.transaction.sendTransaction( txData,'YOUR_WALLET_PRIVATEKEY',true,// Flag to indicate if you want to wait for the transaction to complete50000// Time (in ms) you want to wait for transaction to complete, default will be 300000 (300s));