Working with Tokens
Prerequisite: ERC20ABI JSON file
Retrieve user token balances
import erc20ABI from './ERC20ABI.json';
const tokenAddress = '0xYourTokenAddress'; // Replace with the actual ERC-20 contract address
const userAddress = '0xUserWalletAddress'; // Replace with the user's wallet address
async function getTokenBalance() {
const balance = await client.readContract({
address: tokenAddress,
abi: erc20ABI,
functionName: 'balanceOf', // This is standard ERC-20 function to get balance
args: [userAddress],
});
return balance.toString();
}
// Example usage
getTokenBalance().then(console.log);Retrieve user CHZ balance
Send ERC-20 Tokens to a wallet
Last updated