1

I have already purchased a node on quicknodes and have the API. I was able to retrieve my BNB balance by using this code, however, I would like to retrieve the balance of a specific token in my wallet other than BNB. Could someone point me in the right direction?

var balance = await web3.Eth.GetBalance.SendRequestAsync("ADDRESS GOES HERE");
Console.WriteLine("Balance of Ethereum Foundation's account: " + balance.Value);
Tye Beach
  • 21
  • 3

1 Answers1

1
var web3 = new Web3("provider address");     
string abi = @"[{""inputs"":[{""internalType"":""address"",""name"":""account"",""type"":""address""}],""name"":""balanceOf"",""outputs"":[{""internalType"":""uint256"",""name"":"""",""type"":""uint256""}],""stateMutability"":""view"",""type"":""function""}]";
    string contractaddress = "contractAddress";
    var contract = web3.Eth.GetContract(abi, contractaddress);
    var function = contract.GetFunction("balanceOf");
    string address = "walletAddress";
    BigInteger balance = await function.CallAsync<BigInteger>(address);
Picker
  • 688
  • 1
  • 7
  • 7