Skip to content

Instantly share code, notes, and snippets.

@x5engine
Created April 14, 2020 00:45
Show Gist options
  • Select an option

  • Save x5engine/109430f222f07844e3ca77edd74cbdeb to your computer and use it in GitHub Desktop.

Select an option

Save x5engine/109430f222f07844e3ca77edd74cbdeb to your computer and use it in GitHub Desktop.

Revisions

  1. x5engine created this gist Apr 14, 2020.
    11 changes: 11 additions & 0 deletions USDC balanceOf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    async function getTokenBalance(address) {
    const contractABI = require(baseDir + '/bin/contracts/' + config.CONTRACT_ABI_FILE_NAME.USDC);
    const web3 = new Web3(new Web3.providers.HttpProvider(config.INFURA_NETWORK_URL));

    const USDContractInstance = await new web3.eth.Contract(contractABI, config.CONTRACT_ADDRESS.PROXY);
    let balance = await USDContractInstance.methods.balanceOf(address).call();
    balance = web3.utils.hexToNumber(balance) / Math.pow(10, 6);
    return balance;
    }

    exports.getTokenBalance = getTokenBalance;