How do I get the balance of a specific token on the BSC using Nethereum and Quicknodes?

2.1k Views Asked by At

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);
1

There are 1 best solutions below

0
On
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);