Skip to content

Instantly share code, notes, and snippets.

@juanfranblanco
Last active February 20, 2018 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanfranblanco/6da5ad2b131e7a87736dd154535c9b19 to your computer and use it in GitHub Desktop.
Save juanfranblanco/6da5ad2b131e7a87736dd154535c9b19 to your computer and use it in GitHub Desktop.
Balance Dai
using System;
using System.Numerics;
using System.Threading.Tasks;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts.CQS;
using Nethereum.StandardTokenEIP20;
using Nethereum.Web3;
namespace TestBalance
{
class Program
{
static void Main(string[] args)
{
BalanceAsync().Wait();
BalanceAsync2().Wait();
Console.ReadLine();
}
public static async Task BalanceAsync2()
{
var senderAddress = "0x7345c51439d1C84949f56A6Ad0EcdF3F3f1D2bE2";
var contractAddress = "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359";
//no private key we are not signing anything
var web3 = new Web3("https://mainnet.infura.io");
var standardToken = new StandardTokenService(web3, contractAddress);
var balance = await standardToken.GetBalanceOfAsync<BigInteger>(senderAddress);
Console.WriteLine("Balance of token: " + Web3.Convert.FromWei(balance));
}
public static async Task BalanceAsync()
{
var senderAddress = "0x7345c51439d1C84949f56A6Ad0EcdF3F3f1D2bE2";
var contractAddress = "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359";
//no private key we are not signing anything
var web3 = new Web3("https://mainnet.infura.io");
var balanceOfFunctionMessage = new BalanceOfFunction()
{
Owner = senderAddress,
};
var contractHandler = web3.Eth.GetContractHandler(contractAddress);
var balance = await contractHandler.QueryAsync<BalanceOfFunction,BigInteger>(balanceOfFunctionMessage);
Console.WriteLine("Balance of token: " + Web3.Convert.FromWei(balance));
}
[Function("balanceOf", "uint256")]
public class BalanceOfFunction : ContractMessage
{
[Parameter("address", "_owner", 1)]
public string Owner { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment