This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//intitate web3 here | |
export const getBalanceWithContract = async (address: string) => { | |
let tokenContract = await new web3.eth.Contract(tokenAbi, address); | |
let tokenBalance = await tokenContract.methods.balanceOf(WALLET_PUB).call(); | |
let decimals = await getTokenDecimals(address); | |
tokenBalance = tokenBalance * (1 / Math.pow(10, decimals)); | |
tokenBalance = tokenBalance.toString(); | |
return tokenBalance; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initate the web3 here | |
const getTokenDecimals = async (address: string) => { | |
const tokenContract = await new web3.eth.Contract(tokenAbi, address); | |
let decimals = await tokenContract.methods.decimals().call(); | |
return decimals; | |
}; | |
let decimals = await getTokenDecimals('0xeae2bbbc0000f605bd37a02c7fe346a3b68b03eb') |