public Task<BigInteger> BalanceOfQueryAsync(string owner, BlockParameter blockParameter = null) { var balanceOfFunction = new BalanceOfFunction(); balanceOfFunction.Owner = owner; return ContractHandler.QueryAsync<BalanceOfFunction, BigInteger>(balanceOfFunction, blockParameter); }
/// <summary> /// Logic for your function goes here. /// </summary> /// <param name="context">The HTTP context, containing the request and the response.</param> /// <returns>A task representing the asynchronous operation.</returns> public async Task HandleAsync(HttpContext context) { var web3 = new Nethereum.Web3.Web3("https://mainnet.infura.io/v3/7238211010344719ad14a89db874158c"); // Check the balance of one of the accounts provisioned in our chain, to do that, // we can execute the GetBalance request asynchronously: var balance = await web3.Eth.GetBalance.SendRequestAsync("0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"); await context.Response.WriteAsync("Balance Ether: " + Nethereum.Web3.Web3.Convert.FromWei(balance.Value).ToString()); var balanceOfMessage = new BalanceOfFunction() { Owner = "0x8ee7d9235e01e6b42345120b5d270bdb763624c7" }; //Creating a new query handler var queryHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); //Querying the Maker smart contract https://etherscan.io/address/0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2 var balanceSmartContract = await queryHandler .QueryAsync <BigInteger>("0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2", balanceOfMessage) .ConfigureAwait(false); await context.Response.WriteAsync(" Balance Smart contract: " + Nethereum.Web3.Web3.Convert.FromWei(balanceSmartContract).ToString()); }
public static async Task BalanceAsync() { //hardcoded example to check the balance of a particular w //Replace with any address you want to check the balance of var senderAddress = "0xB..."; //kovan contractaddress var contractAddress = "0x8819a653b6c257b1e3356d902ecb1961d6471dd8"; //replace with your infura.io acct var url = "https://kovan.infura.io/v3/..."; //Enjin token ID, full var CID = "0x7..."; //no private key we are not signing anything (read only mode) var web3 = new Web3(url); var balanceOfFunctionMessage = new BalanceOfFunction() { CryptoID = CID, Owner = senderAddress, }; var balanceHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); var balance = await balanceHandler.QueryAsync <BigInteger>(contractAddress, balanceOfFunctionMessage); Console.WriteLine("Balance of token: " + balance); }
public Task <BigInteger> BalanceOfQueryAsync(BalanceOfFunction balanceOfFunction, BlockParameter blockParameter = null, CancellationToken cancellationToken = default(CancellationToken)) { return(ContractHandler.QueryAsync <BalanceOfFunction, BigInteger>(balanceOfFunction, blockParameter, cancellationToken)); }
public Task <BigInteger> BalanceOfQueryAsync(string Owner, BlockParameter BlockParameter = null) { var BalanceOfFunction = new BalanceOfFunction { Owner = Owner }; return(ContractHandler.QueryAsync <BalanceOfFunction, BigInteger>(BalanceOfFunction, BlockParameter)); }
public Task <BigInteger> BalanceOfQueryAsync(string who, BlockParameter blockParameter = null) { var balanceOfFunction = new BalanceOfFunction(); balanceOfFunction.Who = who; return(ContractHandler.QueryAsync <BalanceOfFunction, BigInteger>(balanceOfFunction, blockParameter)); }
public Task <BigInteger> BalanceOfQueryAsync(string account, BigInteger id, BlockParameter blockParameter = null) { var balanceOfFunction = new BalanceOfFunction(); balanceOfFunction.Account = account; balanceOfFunction.Id = id; return(ContractHandler.QueryAsync <BalanceOfFunction, BigInteger>(balanceOfFunction, blockParameter)); }
public async Task <List <BalanceResult> > GetBalances(int page, int pageSize, string account) { var callList = new List <IMulticallInputOutput>(); var startItem = (page * pageSize); var totaItemsToFetch = startItem + pageSize <= _tokens.Count ? startItem + pageSize : _tokens.Count + startItem; for (int i = startItem; i < totaItemsToFetch; i++) { var balanceOfMessage = new BalanceOfFunction() { Owner = account }; var call = new MulticallInputOutput <BalanceOfFunction, BalanceOfOutputDTO>(balanceOfMessage, _tokens[i].Address); callList.Add(call); } await _web3.Eth.GetMultiQueryHandler().MultiCallAsync(callList.ToArray()).ConfigureAwait(false); var currentBalances = new List <BalanceResult>(); for (int i = startItem; i < totaItemsToFetch; i++) { var balance = ((MulticallInputOutput <BalanceOfFunction, BalanceOfOutputDTO>)callList[i - startItem]).Output.Balance; if (balance > 0) { var balanceResult = new BalanceResult() { Balance = Web3.Convert.FromWei(balance, _tokens[i].Decimals), TokenImage = _tokens[i].LogoURI, TokenName = _tokens[i].Symbol, TokenAdress = _tokens[i].Address, GeckoToken = _geckoTokens.FirstOrDefault(x => x.Symbol.ToLower() == _tokens[i].Symbol.ToLower()) }; currentBalances.Add(balanceResult); } } if (currentBalances.Count > 0) { var ids = currentBalances.Select(x => x.GeckoToken?.Id).Distinct().ToArray(); var prices = await GetPrices(ids).ConfigureAwait(false); foreach (var balance in currentBalances) { if (balance.GeckoToken != null) { var price = prices[balance.GeckoToken.Id.ToLower()]; balance.Price = price["usd"]; balance.Value = balance.Price * balance.Balance; } } } return(currentBalances); }
public async ValueTask <decimal> GetBalanceAsync(string contractAddress, string walletAddress) { var functionMessage = new BalanceOfFunction() { Owner = walletAddress }; return(await _balanceHandler.QueryAsync <long>(contractAddress, functionMessage) / 10000m); }
protected async Task <decimal> GetTokenBalance(string contractAddress, Web3 web3) { var balanceOfMessage = new BalanceOfFunction() { Owner = AccountAddress }; var queryHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); var balance = await queryHandler.QueryAsync <BigInteger>(contractAddress, balanceOfMessage).ConfigureAwait(false); return(Web3.Convert.FromWei(balance)); }
public async Task <BigInteger> QuerySingleContract(IAccount account) { BalanceOfFunction balanceOfFunctionMessage = new BalanceOfFunction() { Owner = account.Address, }; IContractQueryHandler <BalanceOfFunction> balanceHandler = bcNode.Eth.GetContractQueryHandler <BalanceOfFunction>(); BigInteger balance = await balanceHandler.QueryAsync <BigInteger>(contractAddress, balanceOfFunctionMessage); return(balance); }
public async Task <BigInteger> QueryChain(IAccount account) { BalanceOfFunction balanceOfFunctionMessage = new BalanceOfFunction() { Owner = account.Address, }; IContractQueryHandler <BalanceOfFunction> balanceHandler = bcNode.Eth.GetContractQueryHandler <BalanceOfFunction>(); BalanceOfOutputDTO balanceOutput = await balanceHandler.QueryDeserializingToObjectAsync <BalanceOfOutputDTO>(balanceOfFunctionMessage, contractAddress); return(balanceOutput.Balance); }
public async Task <BigInteger> QueryPReviousContractState(IAccount account) { BalanceOfFunction balanceOfFunctionMessage = new BalanceOfFunction() { Owner = account.Address, }; IContractQueryHandler <BalanceOfFunction> balanceHandler = bcNode.Eth.GetContractQueryHandler <BalanceOfFunction>(); BalanceOfOutputDTO balanceOutput = await balanceHandler.QueryDeserializingToObjectAsync <BalanceOfOutputDTO>(balanceOfFunctionMessage, contractAddress, new Nethereum.RPC.Eth.DTOs.BlockParameter(transactionReceipt.BlockNumber)); return(balanceOutput.Balance); }
public Task <BigInteger> BalanceOfQueryAsync(string owner, BlockParameter blockParameter = null, CancellationToken cancellationToken = default(CancellationToken)) { var balanceOfFunction = new BalanceOfFunction(); balanceOfFunction.Owner = owner; return(ContractHandler.QueryAsync <BalanceOfFunction, BigInteger>(balanceOfFunction, blockParameter, cancellationToken)); }
public int GetBalance(string address) { var web3 = new Web3(AppSettings.RpcEndpoint); var contractAddress = AppSettings.CoinContractAddress; var msg = new BalanceOfFunction { Owner = address }; var handler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); return(handler.QueryAsync <int>(msg, contractAddress).Result); }
public static async Task <decimal> GetBalance(string pubKey) { var balanceMessage = new BalanceOfFunction() { Owner = pubKey }; var balance = await handler.QueryAsync <BalanceOfFunction, BigInteger>(balanceMessage); var value = Web3.Convert.FromWeiToBigDecimal(balance); var total = Convert.ToDecimal(value.ToString()); return(total); }
public void admin_account_should_have_tokens_available() { var web3 = new Web3(_settings.RpcEndpoint); var msg = new BalanceOfFunction { Owner = "0x675bb916858f96746d48a98fc9cef49d9a37a5d9" }; var handler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); var contractAddress = _settings.CoinContractAddress; var balance = handler.QueryAsync <int>(msg, contractAddress).Result; Assert.IsTrue(balance > 0); }
public string InvokeERC20GetBalance(string psOwner, string psDummyVal1 = "", string psDummyVal2 = "", string psDummyVal3 = "") { var tokenService = GetERC20TokenService(); var acctOwner = psOwner; var function = new BalanceOfFunction() { Owner = acctOwner }; var balance = tokenService.BalanceOfQueryAsync(function).Result; return(balance.ToString()); }
protected async Task GetTokenBalance() { var web3 = new Web3(RpcUrl); var balanceOfMessage = new BalanceOfFunction() { Owner = AccountAddress }; //Creating a new query handler var queryHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); //Querying the Maker smart contract https://etherscan.io/address/0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2 var balance = await queryHandler.QueryAsync <BigInteger>(ContractAddress, balanceOfMessage).ConfigureAwait(false); Balance = Web3.Convert.FromWei(balance); }
public static async Task <decimal> GetEthContractBalanceAsync(string ethApiUrl, string ethContract, string ethAddress) { var web3 = new Web3(ethApiUrl); var balanceMessage = new BalanceOfFunction { Owner = ethAddress }; var balanceHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); var balance = await balanceHandler.QueryAsync <BigInteger>(ethContract, balanceMessage); var fromTokenBalance = (decimal)(balance / 100000000); return(fromTokenBalance); }
private async Task GetTokenBalancesForAddress(AddressDto enrichedAddress) { var tokenContractsToCheck = this.Configuration.GetSection("Tokens").Get <TokenBalanceDto[]>(); var balanceOfFunctionMessage = new BalanceOfFunction { Owner = enrichedAddress.Address }; var balanceHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); foreach (var tokenContract in tokenContractsToCheck) { var amount = await balanceHandler.QueryAsync <BigInteger>(tokenContract.Address, balanceOfFunctionMessage); tokenContract.Amount = amount.ToString(); enrichedAddress.Balances.Add(tokenContract); } }
public async Task <decimal> GetContractBalanceAsync(EthereumAddress contractAddress, EthereumAddress address, int decimals, ulong?blockNumber = null) { var function = new BalanceOfFunction() { Owner = address, }; var balance = await ExecuteAsync(web3 => { var balanceHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); return(blockNumber.HasValue ? balanceHandler.QueryAsync <BigInteger>(contractAddress, function, new BlockParameter(blockNumber.Value)) : balanceHandler.QueryAsync <BigInteger>(contractAddress, function)); }); return(Web3.Convert.FromWei(balance, decimals)); }
public async Task <decimal> GetBalanceAsync() { Ensure.ArgumentNotNull(this.AccountAddress, "Address"); Ensure.ArgumentNotNull(this.ContractAddress, "ContractAddress"); var web3 = await ethereumHostProvider.GetWeb3Async(); var handler = web3.Eth.GetContractHandler(ContractAddress); var balanceMessage = new BalanceOfFunction() { Owner = AccountAddress }; var balance = await handler.QueryAsync <BalanceOfFunction, BigInteger>(balanceMessage); //assuming all have 18 decimals var value = Web3.Web3.Convert.FromWeiToBigDecimal(balance); return(decimal.Parse(value.ToString())); }
public static async Task BalanceAsync() { //Replace with your own var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c"; var contractAddress = ContractAddress; var url = "https://rinkeby.infura.io/"; //no private key we are not signing anything var web3 = new Web3(url); var balanceOfFunctionMessage = new BalanceOfFunction() { Owner = senderAddress, }; var balanceHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); var balance = await balanceHandler.QueryAsync <BigInteger>(balanceOfFunctionMessage, contractAddress); Console.WriteLine("Balance of token: " + balance); }
public static async Task BalanceAsync() { //Replace with your own var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c"; var contractAddress = ContractAddress; var url = "ws://localhost:8546"; //no private key we are not signing anything (read only mode) var web3 = new Web3.Web3(new WebSocketClient(url)); var balanceOfFunctionMessage = new BalanceOfFunction() { Owner = senderAddress, }; var balanceHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); var balance = await balanceHandler.QueryAsync <BigInteger>(contractAddress, balanceOfFunctionMessage); Console.WriteLine("Balance of token: " + balance); }
public static async Task BalanceAsync() { //Replace with your own var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c"; var contractAddress = ContractAddress; // Note: in this sample, a special INFURA API key is used: `7238211010344719ad14a89db874158c`. If you wish to use this sample in your own project you’ll need to [sign up on INFURA](https://infura.io/register) and use your own key. var url = "https://rinkeby.infura.io/v3/7238211010344719ad14a89db874158c"; //no private key we are not signing anything var web3 = new Web3.Web3(url); var balanceOfFunctionMessage = new BalanceOfFunction() { Owner = senderAddress, }; var balanceHandler = web3.Eth.GetContractQueryHandler <BalanceOfFunction>(); var balance = await balanceHandler.QueryAsync <BigInteger>(contractAddress, balanceOfFunctionMessage); Console.WriteLine("Balance of token: " + balance); }
public async Task Validate( string hubAddress, string recipient, BigInteger gasLimit, BigInteger gasPrice, BigInteger relayFee) { var balanceOf = new BalanceOfFunction() { Target = recipient }; var balanceOfHandler = _ethApiContractService.GetContractQueryHandler <BalanceOfFunction>(); var balance = await balanceOfHandler .QueryAsync <BigInteger>(hubAddress, balanceOf) .ConfigureAwait(false); if (balance.IsZero) { throw new GSNLowBalanceException($"Recipient {recipient} has no funds for paying for relayed calls on the relay hub."); } var maxPossibleCharge = new MaxPossibleChargeFunction() { RelayedCallStipend = gasLimit, GasPriceParam = gasPrice, TransactionFee = relayFee }; var maxPossibleChargeHandler = _ethApiContractService.GetContractQueryHandler <MaxPossibleChargeFunction>(); var maxCharge = await maxPossibleChargeHandler .QueryAsync <BigInteger>(hubAddress, maxPossibleCharge) .ConfigureAwait(false); if (maxCharge.CompareTo(balance) == 1) { throw new GSNLowBalanceException($"Recipient {recipient} has not enough funds for paying for this relayed call (has {balance}, requires {maxCharge})."); } }
public async Task Transfering_ShouldIncreaseTheBalanceOfReceiver(int valueToSend) { var contractDeploymentDefault = SimpleStandardContractTest.GetDeploymentMessage(); Assert.False(valueToSend > contractDeploymentDefault.InitialAmount, "value to send is bigger than the total supply, please adjust the test data"); GivenADeployedContract(contractDeploymentDefault); var receiver = SimpleStandardContractTest.ReceiverAddress; var transferMessage = new TransferFunction() { Value = valueToSend, FromAddress = DefaultTestAccountConstants.Address, To = receiver, }; var expectedEvent = new TransferEventDTO() { From = DefaultTestAccountConstants.Address.ToLower(), To = SimpleStandardContractTest.ReceiverAddress.ToLower(), Value = valueToSend }; GivenATransaction(transferMessage). ThenExpectAnEvent(expectedEvent); var queryBalanceReceiverMessage = new BalanceOfFunction() { Owner = ReceiverAddress }; var balanceOfExpectedResult = new BalanceOfOutputDTO() { Balance = valueToSend }; WhenQuerying <BalanceOfFunction, BalanceOfOutputDTO>(queryBalanceReceiverMessage) .ThenExpectResult(balanceOfExpectedResult); }
public Task <BigInteger> BalanceOfQueryAsync(BalanceOfFunction balanceOfFunction, BlockParameter blockParameter = null) { return(ContractHandler.QueryAsync <BalanceOfFunction, BigInteger>(balanceOfFunction, blockParameter)); }