getBalance
getBalance
The getBalance
the function retrieves the balance associated with a specific Ethereum address for the ERC20 token it corresponds to. This function is a part of the ERC20Instance object, which is acquired through the getERC20Instance
method of the ZkyugaClient
.
Method Signature
getBalance(address: string): Promise<BigNumber>
Parameters
address
string
The Ethereum address for which the balance needs to be retrieved.
Returns
A
Promise
that resolves to aBigNumber
representing the balance of the given Ethereum address in terms of the ERC20 token.
Usage Example
Begin by instantiating the desired ERC20 token contract using its contract address:
const erc20 = zkyugaClient.getERC20Instance("0x3f36f83b0d43EE58FAE33D58A182a14aB9aE5876");
Then, invoke the getBalance function, providing the target Ethereum address:
const address = "0x3f36f83b0d43EE58FAE33D58A182a14aB9aE5876";
const balance = await erc20.getBalance(address);
console.log(`Balance: ${balance.toString()}`);
Notes
Ensure the provided Ethereum address is valid to avoid potential errors or inaccurate data.
The returned balance is denominated in the smallest unit of the ERC20 token (e.g., Wei for Ether). You may need to convert it to a more readable format using the token's decimals.
Last updated