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

Class Assets

packages/cardpay-sdk/sdk/assets.ts:11–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9}
10
11export default class Assets implements IAssets {
12 constructor(private web3: Web3) {}
13
14 async getNativeTokenBalance(userAddress?: string): Promise<string> {
15 let address = userAddress ?? (await this.web3.eth.getAccounts())[0];
16
17 return this.web3.eth.getBalance(address);
18 }
19
20 async getBalanceForToken(tokenAddress: string, tokenHolderAddress?: string): Promise<string> {
21 let address = tokenHolderAddress ?? (await this.web3.eth.getAccounts())[0];
22 const tokenContract = new this.web3.eth.Contract(ERC20ABI as AbiItem[], tokenAddress);
23
24 return tokenContract.methods.balanceOf(address).call();
25 }
26
27 async getTokenInfo(tokenAddress: string): Promise<{ decimals: number; name: string; symbol: string }> {
28 const tokenContract = new this.web3.eth.Contract(ERC20ABI as AbiItem[], tokenAddress);
29 return {
30 decimals: Number(await tokenContract.methods.decimals().call()),
31 name: await tokenContract.methods.name().call(),
32 symbol: await tokenContract.methods.symbol().call(),
33 };
34 }
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected