Skip to content

Instantly share code, notes, and snippets.

@syshen
Created February 15, 2023 10:34

Revisions

  1. syshen created this gist Feb 15, 2023.
    33 changes: 33 additions & 0 deletions token-balance.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    const Web3 = require('web3');

    const web3 = new Web3(new Web3.providers.HttpProvider('<Node API endpoint>'));
    const balanceOfABI = [
    {
    "constant": true,
    "inputs": [
    {
    "name": "_owner",
    "type": "address"
    }
    ],
    "name": "balanceOf",
    "outputs": [
    {
    "name": "balance",
    "type": "uint256"
    }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
    },
    ];
    const usdt = new web3.eth.Contract(balanceOfABI, '0xdAC17F958D2ee523a2206206994597C13D831ec7');

    async function getUSDTBalance(walletAddress) {
    const result = await usdt.methods.balanceOf(walletAddress).call({}, '16632997');
    console.log(result);
    }

    getUSDTBalance('0xDFd5293D8e347dFe59E90eFd55b2956a1343963d').then(console.log).catch(console.error);