public async Task GetLogs() { string[][] mockedResponses = { new[] { "eth_getLogs", "eth_getLogs.json" } }; IN3 in3 = _factory.CreateIn3(mockedResponses); LogFilter filter = new LogFilter { FromBlock = DataTypeConverter.HexStringToBigint("0x834B77"), ToBlock = DataTypeConverter.HexStringToBigint("0x834B77"), Address = "0xdac17f958d2ee523a2206206994597c13d831ec7" }; Log[] response = await in3.Eth1.GetLogs(filter); Assert.That(response[0].TransactionHash, Is.EqualTo("0x20be6d27ed6a4c99c5dbeeb9081e114a9b400c52b80c4d10096c94ad7d3c1af6")); }
public void HexStringToBigint() { string n1 = "-0x0C5F387CA52B8F"; string n2 = "0x0"; string n3 = "0x0F"; string n4 = "0x11"; string n5 = "0x961e2e"; string n6 = "0x24e160300"; BigInteger res1 = -3482395934534543; BigInteger res2 = 0; BigInteger res3 = 15; BigInteger res4 = 17; BigInteger res5 = 9838126; BigInteger res6 = 9900000000; Assert.That(DataTypeConverter.HexStringToBigint(n1), Is.EqualTo(res1)); Assert.That(DataTypeConverter.HexStringToBigint(n2), Is.EqualTo(res2)); Assert.That(DataTypeConverter.HexStringToBigint(n3), Is.EqualTo(res3)); Assert.That(DataTypeConverter.HexStringToBigint(n4), Is.EqualTo(res4)); Assert.That(DataTypeConverter.HexStringToBigint(n5), Is.EqualTo(res5)); Assert.That(DataTypeConverter.HexStringToBigint(n6), Is.EqualTo(res6)); }
public static async Task Main() { // Set it to mainnet IN3 mainnetClient = IN3.ForChain(Chain.Mainnet); ClientConfiguration cfg = mainnetClient.Configuration; cfg.Proof = Proof.Standard; string contractAddress = "0x2736D225f85740f42D17987100dc8d58e9e16252"; // Create the query transaction TransactionRequest serverCountQuery = new TransactionRequest(); serverCountQuery.To = contractAddress; // Define the function and the parameters to query the total in3 servers serverCountQuery.Function = "totalServers():uint256"; serverCountQuery.Params = new object[0]; string[] serverCountResult = (string[])await mainnetClient.Eth1.Call(serverCountQuery, BlockParameter.Latest); BigInteger servers = DataTypeConverter.HexStringToBigint(serverCountResult[0]); for (int i = 0; i < servers; i++) { TransactionRequest serverDetailQuery = new TransactionRequest(); serverDetailQuery.To = contractAddress; // Define the function and the parameters to query the in3 servers detail serverDetailQuery.Function = "servers(uint256):(string,address,uint32,uint256,uint256,address)"; serverDetailQuery.Params = new object[] { i }; // index of the server (uint256) as per solidity function signature string[] serverDetailResult = (string[])await mainnetClient.Eth1.Call(serverDetailQuery, BlockParameter.Latest); Console.Out.WriteLine($"Server url: {serverDetailResult[0]}"); } }
/// <summary> /// Returns the number of the most recent block the in3 network can collect signatures to verify. /// Can be changed by <see cref="Configuration.ClientConfiguration.ReplaceLatestBlock" />. /// If you need the very latest block, change <see cref="Configuration.ClientConfiguration.SignatureCount" /> to <see langword="0"/>. /// </summary> /// <returns>The number of the block.</returns> public async Task <BigInteger> BlockNumber() { string jsonResponse = await _in3.SendRpc(EthBlockNumber, new object[] { }); return(DataTypeConverter.HexStringToBigint(RpcHandler.From <string>(jsonResponse))); }
/// <summary> /// Gas estimation for transaction. Used to fill transaction.gas field. Check RawTransaction docs for more on gas. /// </summary> /// <param name="request">The transaction request whose cost will be estimated.</param> /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param> /// <returns>Estimated gas in Wei.</returns> public async Task <long> EstimateGas(TransactionRequest request, BigInteger blockNumber) { string jsonResponse = await _in3.SendRpc(EthEstimateGas, new object[] { await MapTransactionToRpc(request), BlockParameter.AsString(blockNumber) }); return((long)DataTypeConverter.HexStringToBigint(RpcHandler.From <string>(jsonResponse))); }
/// <summary> /// Creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call <see cref="Eth1.Api.GetFilterChangesFromLogs" />. /// Filters are event catchers running on the Ethereum Client. Incubed has a client-side implementation. /// An event will be stored in case it is within to and from blocks, or in the block of blockhash, contains a /// transaction to the designed address, and has a word listed on topics. /// </summary> /// <returns>The filter id.</returns> /// <remarks> /// <para>Use the returned filter id to perform other filter operations.</para> /// </remarks> public async Task <long> NewBlockFilter() { string jsonResponse = await _in3.SendRpc(EthNewBlockFilter, new object[] { }); return((long)DataTypeConverter.HexStringToBigint(RpcHandler.From <string>(jsonResponse))); }
/// <summary> /// Returns the balance of the account of given <paramref name="address" />. /// </summary> /// <param name="address">Address to check for balance.</param> /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param> /// <returns>The current balance in wei.</returns> public async Task <BigInteger> GetBalance(string address, BigInteger blockNumber) { string jsonResponse = await _in3.SendRpc(EthGetBalance, new object[] { address, BlockParameter.AsString(blockNumber) }); return(DataTypeConverter.HexStringToBigint(RpcHandler.From <string>(jsonResponse))); }
/// <summary> /// Get the <see cref="Chain" /> which the client is currently connected to. /// </summary> /// <returns>The <see cref="Chain" />.</returns> public async Task <Chain> GetChainId() { string jsonResponse = await _in3.SendRpc(EthChainId, new object[] { }); return((Chain)(long)DataTypeConverter.HexStringToBigint(RpcHandler.From <string>(jsonResponse))); }
/// <summary> /// The current gas price in Wei (1 ETH equals 1000000000000000000 Wei ). /// </summary> /// <returns>The gas price.</returns> public async Task <long> GetGasPrice() { string jsonResponse = await _in3.SendRpc(EthGasPrice, new object[] { }); return((long)DataTypeConverter.HexStringToBigint(RpcHandler.From <string>(jsonResponse))); }