Thie Assets API is used issue queries for native coin balances and ERC-20 token balances, as well as to get ERC-20 token info. The Assets API can be obtained from getSDK() with a Web3 instance that is configured to operate on either layer 1 or layer 2, depending on where the asset you wish to query lives.

Example

import { getSDK } from "@cardstack/cardpay-sdk";
let web3 = new Web3(myProvider);
let assetAPI = await getSDK('Assets', web3);

Hierarchy

  • AssetsClass

Implements

Constructors

Properties

web3: default

Methods

  • This call returns the balance in native token for the specified address. So in Ethereum mainnet, this would be the ether balance. In Gnosis Chain this would be the XDAI token balance.

    Returns

    promise for the native token amount as a string in native units (usually wei). If no address is provided, then the balance of the first address in the wallet will be retrieved.

    Example

    let assetsAPI = await getSDK('Assets', web3);
    let etherBalance = await assetsAPI.getNativeTokenBalance(walletAddress);

    Parameters

    • Optional userAddress: string

    Returns Promise<string>

  • This call returns the balance in for an ERC-20 token from the specified address.

    Returns

    a promise for the token amount as a string in native units of the token (usually) wei). If no token holder address is provided, then the balance of the first address in the wallet will be retrieved.

    Example

    let assetsAPI = await getSDK('Assets', web3);
    let cardBalance = await assetsAPI.getBalanceForToken(cardTokenAddress, walletAddress);

    Parameters

    • tokenAddress: string
    • Optional tokenHolderAddress: string

    Returns Promise<string>

  • This call returns ERC-20 token information: the token name, the token symbol, and the token decimals for an ERC-20 token.

    Example

    let assetsAPI = await getSDK('Assets', web3);
    let { name, symbol, decimals } = await assetsAPI.getTokenInfo(cardTokenAddress);

    Parameters

    • tokenAddress: string

    Returns Promise<{
        decimals: number;
        name: string;
        symbol: string;
    }>

Generated using TypeDoc