getBalance
The getBalance
method fetches the balance of a specific Ethereum address for the associated ERC20 token. This method belongs to the ERC20Instance
object returned by the getERC20Instance
method of EdexaClient
.
Method Signature
getBalance(address: string): Promise<BigNumber>
Parameters
Parameter | Type | Description |
---|---|---|
address | string | The Ethereum address for which the balance needs to be retrieved. |
Returns
- A
Promise
resolving to aBigNumber
representing the balance of the provided Ethereum address in terms of the ERC20 token.
Usage Example
First, instantiate the desired ERC20 token contract using its contract address:
const erc20 = edexaClient.getERC20Instance("0x4DB67190e915C15aA8CCd889F35185D73dA37878");
Then, call the getBalance
method by providing the desired Ethereum address:
const address = "0xF6E234C71F1bB45ABa51c977137eF090b2df2Fe5";
const balance = await erc20.getBalance(address);
console.log(`Balance: ${balance.toString()}`);
Notes
- Ensure that the Ethereum address provided is valid; otherwise, the method might throw an error or return incorrect data.
- The returned balance will be in the smallest unit of the ERC20 token (e.g., Wei for Ether). You might need to convert it to a more readable format using the token's decimals.