public Eth(RpcClient client):base(client) { this.Client = client; DeployContract = new DeployContract(client); Accounts = new EthAccounts(client); CoinBase = new EthCoinBase(client); GasPrice = new EthGasPrice(client); GetBalance = new EthGetBalance(client); GetCode = new EthGetCode(client); GetStorageAt = new EthGetStorageAt(client); ProtocolVersion = new EthProtocolVersion(client); Sign = new EthSign(client); Syncing = new EthSyncing(client); Transactions = new EthTransactionsService(client); Filters = new EthFilterService(client); Blocks = new EthBlockService(client); Uncles = new EthUncleService(client); Mining = new EthMiningService(client); Compile = new EthCompilerService(client); this.DefaultBlock = BlockParameter.CreateLatest(); }
public Eth(RpcClient client) : base(client) { this.Client = client; DeployContract = new DeployContract(client); Accounts = new EthAccounts(client); CoinBase = new EthCoinBase(client); GasPrice = new EthGasPrice(client); GetBalance = new EthGetBalance(client); GetCode = new EthGetCode(client); GetStorageAt = new EthGetStorageAt(client); ProtocolVersion = new EthProtocolVersion(client); Sign = new EthSign(client); Syncing = new EthSyncing(client); Transactions = new EthTransactionsService(client); Filters = new EthFilterService(client); Blocks = new EthBlockService(client); Uncles = new EthUncleService(client); Mining = new EthMiningService(client); Compile = new EthCompilerService(client); this.DefaultBlock = BlockParameter.CreateLatest(); }
public EthApiService(IClient client, ITransactionManager transactionManager) : base(client) { Client = client; ChainId = new EthChainId(client); Accounts = new EthAccounts(client); CoinBase = new EthCoinBase(client); GasPrice = new EthGasPrice(client); GetBalance = new EthGetBalance(client); GetCode = new EthGetCode(client); GetStorageAt = new EthGetStorageAt(client); ProtocolVersion = new EthProtocolVersion(client); Sign = new EthSign(client); Syncing = new EthSyncing(client); Transactions = new EthApiTransactionsService(client); Filters = new EthApiFilterService(client); Blocks = new EthApiBlockService(client); Uncles = new EthApiUncleService(client); Mining = new EthApiMiningService(client); Compile = new EthApiCompilerService(client); DefaultBlock = BlockParameter.CreateLatest(); TransactionManager = transactionManager; TransactionManager.Client = client; //Ensure is the same }
public async void ShouldReturnBalanceBiggerThanZeroForCurrentBlock() { var blockNumber = await(new EthBlockNumber(Client)).SendRequestAsync(); var ethGetBalance = new EthGetBalance(Client); var result = await ethGetBalance.SendRequestAsync(Settings.GetDefaultAccount(), new BlockParameter(blockNumber)); //Default account has balance Assert.True(result.Value > 0); }
public async Task <decimal> CalculateTotalAmountToTransferWholeBalanceInEther(string address, decimal gasPriceGwei, BigInteger?gas = null) { var ethGetBalance = new EthGetBalance(_transactionManager.Client); var currentBalance = await ethGetBalance.SendRequestAsync(address); var gasPrice = UnitConversion.Convert.ToWei(gasPriceGwei, UnitConversion.EthUnit.Gwei); var gasAmount = gas ?? _transactionManager.DefaultGas; var totalAmount = currentBalance.Value - (gasAmount * gasPrice); return(UnitConversion.Convert.FromWei(totalAmount)); }
public async Task <decimal> CalculateTotalAmountToTransferWholeBalanceInEtherAsync(string address, BigInteger maxFeePerGas, BigInteger?gas = null) { var ethGetBalance = new EthGetBalance(_transactionManager.Client); var currentBalance = await ethGetBalance.SendRequestAsync(address).ConfigureAwait(false); var gasAmount = gas ?? _transactionManager.DefaultGas; var totalAmount = currentBalance.Value - (gasAmount * maxFeePerGas); if (totalAmount <= 0) { throw new Exception("Insufficient balance to make a transfer"); } return(UnitConversion.Convert.FromWei(totalAmount)); }
public override async Task <HexBigInteger> ExecuteAsync(IClient client) { var ethGetBalance = new EthGetBalance(client); return(await ethGetBalance.SendRequestAsync(Settings.GetDefaultAccount())); }
/// <summary> /// Gets the ether balance of an address. /// </summary> /// <param name="address"> The address to check for the ether balance. </param> /// <returns> Task which returns the decimal ether balance of the address. </returns> public static async Task <decimal> GetEtherBalance(string address) { EthGetBalance ethGetBalance = new EthGetBalance(NetworkProvider.GetWeb3().Client); return(SolidityUtils.ConvertFromUInt((await ethGetBalance.SendRequestAsync(address)).Value, 18)); }
public async Task <object> ExecuteTestAsync(IClient client) { var ethGetBalance = new EthGetBalance(client); return(await ethGetBalance.SendRequestAsync("0x12890d2cce102216644c59dae5baed380d84830c")); }
public async Task<dynamic> ExecuteTestAsync(RpcClient client) { var ethGetBalance = new EthGetBalance(client); return await ethGetBalance.SendRequestAsync( "0x12890d2cce102216644c59dae5baed380d84830c"); }
static void Main(string[] args) { var account = new ManagedAccount("0x12890d2cce102216644c59daE5baed380d84830c", "password"); var clientws = new WebSocketClient("ws://127.0.0.1:8546"); var web3ws = new Web3.Web3(account, clientws); var res = web3ws.Eth.Blocks.GetBlockNumber.SendRequestAsync().Result; //task cancelled exception var clientipc = new IpcClient("jsonrpc.ipc"); var web3ipc = new Web3.Web3(account, clientipc); var resIpc = web3ws.Eth.Blocks.GetBlockNumber.SendRequestAsync().Result; var client = new StreamingWebSocketClient("ws://127.0.0.1:8546"); client.Error += Client_Error; var accountBalanceSubscription = new ParityPubSubObservableSubscription <HexBigInteger>(client); var ethBalanceRequest = new EthGetBalance().BuildRequest("0x12890d2cce102216644c59daE5baed380d84830c", BlockParameter.CreateLatest()); accountBalanceSubscription.GetSubscriptionDataResponsesAsObservable().Subscribe(newBalance => Console.WriteLine("New Balance: " + newBalance.Value.ToString()), onError => Console.WriteLine("Error:" + onError.Message)); accountBalanceSubscription.GetSubscribeResponseAsObservable() .Subscribe(x => Console.WriteLine("SubscriptionId:" + x)); client.StartAsync().Wait(); accountBalanceSubscription.SubscribeAsync(ethBalanceRequest).Wait(); // do transfer var web3 = new Web3.Web3(new Account("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7")); for (int i = 0; i < 10; i++) { web3.Eth.GetEtherTransferService() .TransferEtherAndWaitForReceiptAsync("0x12890d2cce102216644c59daE5baed380d848306", 10).Wait(); } client.StopAsync().Wait(); var accountBalanceSubscription2 = new ParityPubSubObservableSubscription <HexBigInteger>(client); var ethBalanceRequest2 = new EthGetBalance().BuildRequest("0x12890d2cce102216644c59daE5baed380d84830c", BlockParameter.CreateLatest()); accountBalanceSubscription2.GetSubscriptionDataResponsesAsObservable().Subscribe(newBalance => Console.WriteLine("New Balance: " + newBalance.Value.ToString())); accountBalanceSubscription2.GetSubscribeResponseAsObservable() .Subscribe(x => Console.WriteLine("SubscriptionId:" + x)); client.StartAsync().Wait(); accountBalanceSubscription2.SubscribeAsync(ethBalanceRequest2).Wait(); for (int i = 0; i < 10; i++) { web3.Eth.GetEtherTransferService() .TransferEtherAndWaitForReceiptAsync("0x12890d2cce102216644c59daE5baed380d848306", 10).Wait(); } }