0

Is this possible with and without knowing the private key of the wallet.

1

You may try this...

function getBalanceOf(tokenAddress, walletAddress) {

// The minimum ABI to get ERC20 Token balance
let minABI = [
  // balanceOf
  {
    "constant":true,
    "inputs":[{"name":"_owner","type":"address"}],
    "name":"balanceOf",
    "outputs":[{"name":"balance","type":"uint256"}],
    "type":"function"
  },
  // decimals
  {
    "constant":true,
    "inputs":[],
    "name":"decimals",
    "outputs":[{"name":"","type":"uint8"}],
    "type":"function"
  }
];

if (typeof web3 !== 'undefined') {
        web3 = new Web3(web3.currentProvider);
    } else {
        // set the provider you want from Web3.providers
        web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/placeyourAPIkeyhere"));
    }

// Get ERC20 Token contract instance
let contract = new web3.eth.Contract(minABI, tokenAddress);

// Call balanceOf function
contract.methods.balanceOf(walletAddress).call().then(function (result) {

//Do something that you want here when you get a result/balance

});

}

0

Sure, this is possible. Something like this:

var tokenContract = new web3.eth.Contract([
  {
    "constant": true,
    "inputs": [
      {
        "name": "_owner",
        "type": "address"
      }
    ],
    "name": "balanceOf",
    "outputs": [
      {
        "name": "balance",
        "type": "uint256"
      }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
  }], '0x<address of token contract>');
var balance = tokenContract.methods.balanceOf.call ('0x<address of token holder>');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.