( network: string, tokenAddress: string | undefined, mnemonic?: string )
| 3 | import { getWeb3 } from './utils'; |
| 4 | |
| 5 | export const viewTokenBalance = async ( |
| 6 | network: string, |
| 7 | tokenAddress: string | undefined, |
| 8 | mnemonic?: string |
| 9 | ): Promise<void> => { |
| 10 | let web3 = await getWeb3(network, mnemonic); |
| 11 | let assets = await getSDK('Assets', web3); |
| 12 | |
| 13 | if (!tokenAddress) { |
| 14 | const nativeTokenSymbol = getConstantByNetwork('nativeTokenSymbol', network); |
| 15 | |
| 16 | const balance = await assets.getNativeTokenBalance(); |
| 17 | |
| 18 | console.log(`${nativeTokenSymbol} balance - ${web3.utils.fromWei(balance)}`); |
| 19 | } else { |
| 20 | const balance = await assets.getBalanceForToken(tokenAddress); |
| 21 | const tokenContract = new web3.eth.Contract(ERC20ABI as AbiItem[], tokenAddress); |
| 22 | const tokenSymbol = await tokenContract.methods.symbol().call(); |
| 23 | |
| 24 | console.log(`${tokenSymbol} balance - ${web3.utils.fromWei(balance)}`); |
| 25 | } |
| 26 | }; |
no test coverage detected