public async Task SendTransactionAndWait() { string[][] mockedResponses = { new[] { "eth_gasPrice", "eth_gasPrice.json" }, new[] { "eth_estimateGas", "eth_estimateGas.json" }, new[] { "eth_getTransactionCount", "eth_getTransactionCount.json" }, new[] { "eth_sendRawTransaction", "eth_sendRawTransaction.json" }, new[] { "eth_getTransactionReceipt", "eth_getTransactionReceipt.json" } }; IN3 in3 = _factory.CreateIn3(mockedResponses); string pk = "0x0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1"; SimpleWallet sw = (SimpleWallet)in3.Signer; string from = sw.AddRawKey(pk); TransactionRequest request = new TransactionRequest { From = @from, To = "0x3940256B93c4BE0B1d5931A6A036608c25706B0c", Gas = 21000, Value = 100000000 }; TransactionReceipt receipt = await in3.Eth1.SendTransactionAndWait(request); Assert.That(receipt.To, Is.EqualTo("0x5b8174e20996ec743f01d3b55a35dd376429c596")); Assert.That(receipt.Status); Assert.That(receipt.Logs[0].Address, Is.EqualTo("0x5b8174e20996ec743f01d3b55a35dd376429c596")); }
public async Task SendTransaction() { string[][] mockedResponses = { new[] { "eth_gasPrice", "eth_gasPrice.json" }, new[] { "eth_estimateGas", "eth_estimateGas.json" }, new[] { "eth_getTransactionCount", "eth_getTransactionCount.json" }, new[] { "eth_sendRawTransaction", "eth_sendRawTransaction.json" } }; IN3 in3 = _factory.CreateIn3(mockedResponses); string expectedHash = "0xd5651b7c0b396c16ad9dc44ef0770aa215ca795702158395713facfbc9b55f38"; string pk = "0x0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1"; SimpleWallet sw = (SimpleWallet)in3.Signer; string from = sw.AddRawKey(pk); TransactionRequest request = new TransactionRequest { From = @from, To = "0x3940256B93c4BE0B1d5931A6A036608c25706B0c", Gas = 21000, Value = 100000000 }; object txHash = await in3.Eth1.SendTransaction(request); Assert.That(txHash, Is.EqualTo(expectedHash)); }
public async Task Sign() { string pk = "0x889dbed9450f7a4b68e0732ccb7cd016dab158e6946d16158f2736fda1143ca6"; string address = _wallet.AddRawKey(pk); string dataToSign = "1e194c68360307cfb715bf17878791ad1ced8da7d2e5f42b691074c577f41eac"; string expectedSignerData = "0xf16dcaa830a3f710e28444df7df85fa927d8a66f789196fc2a3b934c829dbcaa5329be0711daba3b0c85ab23f1adb32c4e88fd8cb42b951d3be40af1bbd92e7400"; string signedData = await _wallet.Sign(dataToSign, address); Assert.That(address, Is.EqualTo("0x082977959d0C5A1bA627720ac753Ec2ADB5Bd7d0".ToLower())); Assert.That(signedData, Is.EqualTo(expectedSignerData)); }
public async Task EstimateGas() { string[][] mockedResponses = { new[] { "eth_estimateGas", "eth_estimateGas.json" } }; IN3 in3 = _factory.CreateIn3(mockedResponses); string pk = "0x0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1"; SimpleWallet wallet = (SimpleWallet)in3.Signer; string from = wallet.AddRawKey(pk); long expectedGasEstimate = 21000; TransactionRequest tx = new TransactionRequest { GasPrice = 1, From = @from, To = "0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8" }; long gasEstimate = await in3.Eth1.EstimateGas(tx, BlockParameter.Latest); Assert.That(gasEstimate, Is.EqualTo(expectedGasEstimate)); }
static async Task Main() { IN3 goerliClient = IN3.ForChain(Chain.Goerli); string myPrivateKey = "0x0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1"; string receivingAddress = "0x6FA33809667A99A805b610C49EE2042863b1bb83"; // Get the wallet, which is the default signer. SimpleWallet myAccountWallet = (SimpleWallet)goerliClient.Signer; string myAccount = myAccountWallet.AddRawKey(myPrivateKey); // Create the transaction request TransactionRequest transferWei = new TransactionRequest(); transferWei.To = receivingAddress; transferWei.From = myAccount; transferWei.Value = 300; // Get the current gas prices long currentGasPrice = await goerliClient.Eth1.GetGasPrice(); transferWei.GasPrice = currentGasPrice; long estimatedSpentGas = await goerliClient.Eth1.EstimateGas(transferWei, BlockParameter.Latest); Console.Out.WriteLine($"Estimated gas to spend: {estimatedSpentGas}"); string transactionHash = await goerliClient.Eth1.SendTransaction(transferWei); Console.Out.WriteLine($"Transaction {transactionHash} sent."); Thread.Sleep(30000); TransactionReceipt receipt = await goerliClient.Eth1.GetTransactionReceipt(transactionHash); Console.Out.WriteLine($"Transaction {transactionHash} mined on block {receipt.BlockNumber}."); }