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.
const topic = keccak256('Transfer(address,address,uint256)');
const filterId = await kardiaClient.kaiChain.newFilter({
fromBlock: 200000,
topics: [topic]
})
// To get all logs
const allLogs = await kardiaClient.kaiChain.getFilterLogs(filterId);
// To get logs since last poll
const logs = await kardiaClient.kaiChain.getFilterChanges(filterId);
KRC20 Module
Get KRC20 balance of a wallet
import KardiaClient from 'kardia-js-sdk';
const RPC_ENDPOINT = 'YOUR_RPC_ENDPOINT';
const kardiaClient = new KardiaClient({ endpoint: RPC_ENDPOINT });
const krc20Instance = kardiaClient.krc20;
// Fetch KRC20 token's data from smart contract
await 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 code
const decimals = krc20Instance.getDecimals();
const parsedBalance = balance / 10 ** decimals;
Send a KRC20 transaction
import KardiaClient from 'kardia-js-sdk';
const RPC_ENDPOINT = 'YOUR_RPC_ENDPOINT';
const kardiaClient = new KardiaClient({ 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
import KardiaClient from 'kardia-js-sdk';
const RPC_ENDPOINT = 'YOUR_RPC_ENDPOINT';
const kardiaClient = new KardiaClient({ endpoint: RPC_ENDPOINT });
// Get your wallet's latest nonce
const 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 immediately
const 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 code
const txResult = await kardiaClient.transaction.sendTransaction(
txData,
'YOUR_WALLET_PRIVATEKEY',
true, // Flag to indicate if you want to wait for the transaction to complete
50000 // Time (in ms) you want to wait for transaction to complete, default will be 300000 (300s)
);