MCPcopy Create free account
hub / github.com/cardstack/cardstack / viewTokenBalance

Function viewTokenBalance

packages/cardpay-cli/assets.ts:5–26  ·  view source on GitHub ↗
(
  network: string,
  tokenAddress: string | undefined,
  mnemonic?: string
)

Source from the content-addressed store, hash-verified

3import { getWeb3 } from './utils';
4
5export 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};

Callers 1

index.tsFile · 0.90

Calls 7

getWeb3Function · 0.90
getSDKFunction · 0.90
getConstantByNetworkFunction · 0.90
symbolMethod · 0.80
getNativeTokenBalanceMethod · 0.65
getBalanceForTokenMethod · 0.65
logMethod · 0.45

Tested by

no test coverage detected