static public async Task <bool> InteractWithExistingContractWithEtherAndEventsExample(Web3 web3, string fromAddress, string fromPassword, string contractAddress, string contractAbi, long amountWei) { Console.WriteLine("InteractWithExistingContractWithEtherAndEventsExample:"); string extraData = DateTime.Now.ToString() + " extraData contract"; var extraDataHex = new HexUTF8String(extraData).HexValue; var ti = new Nethereum.RPC.Eth.DTOs.TransactionInput(extraDataHex, contractAddress, fromAddress, new HexBigInteger(900000), new HexBigInteger(amountWei)); var contract = web3.Eth.GetContract(contractAbi, contractAddress); var depositFunction = contract.GetFunction("deposit"); var depositReceiptEvent = contract.GetEvent("DepositReceipt"); var filterAllDepositReceipt = await depositReceiptEvent.CreateFilterAsync(); var unlockResult = await web3.Personal.UnlockAccount.SendRequestAsync(fromAddress, fromPassword, UNLOCK_TIMEOUT); var txHash2 = await depositFunction.SendTransactionAsync(ti, "1234-5678-9012-3456"); // first transfer ti.Value = new HexBigInteger(357); txHash2 = await depositFunction.SendTransactionAsync(ti, "1234-5678-9012-3456"); // second transfer Console.WriteLine("txHash2:\t" + txHash2.ToString()); var txReceipt2 = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txHash2); int timeoutCount = 0; while (txReceipt2 == null && timeoutCount < MAX_TIMEOUT) { Console.WriteLine("Sleeping..."); Thread.Sleep(SLEEP_TIME); txReceipt2 = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txHash2); timeoutCount += SLEEP_TIME; } Console.WriteLine("timeoutCount:\t" + timeoutCount.ToString()); Console.WriteLine("fromAddress:\t" + fromAddress.ToString()); Console.WriteLine("contractAddress:\t" + contractAddress.ToString()); Console.WriteLine("amountWei:\t" + amountWei.ToString()); Console.WriteLine("extraData:\t" + extraData.ToString()); Console.WriteLine("extraDataHex:\t" + extraDataHex.ToString()); Console.WriteLine("txHash2:\t" + txHash2.ToString()); var logDepositReceipts = await depositReceiptEvent.GetFilterChanges <FunctionOutputHelpers.DepositReceiptArgs>(filterAllDepositReceipt); foreach (var dra in logDepositReceipts) { var dt = Helpers.UnixTimeStampToDateTime((double)dra.Event.timestamp); Console.WriteLine("depositReceiptEvent:\t" + dt.ToString() + " " + dra.Event.from.ToString() + " " + dra.Event.id.ToString() + " " + dra.Event.value.ToString()); } return(true); }
static public async Task <string> SendEtherToAccountWithExtraDataExample(Web3 web3, string fromAddress, string fromPassword, string toAddress, long amountWei, string extraData) { Console.WriteLine("SendEtherToAccountWithExtraDataExample:"); var extraDataHex = new HexUTF8String(extraData).HexValue; var ti = new Nethereum.RPC.Eth.DTOs.TransactionInput(extraDataHex, toAddress, fromAddress, new HexBigInteger(900000), new HexBigInteger(amountWei)); var unlockResult = await web3.Personal.UnlockAccount.SendRequestAsync(fromAddress, fromPassword, UNLOCK_TIMEOUT); var sendTxHash = await web3.Eth.TransactionManager.SendTransactionAsync(ti); Console.WriteLine("fromAddress:\t" + fromAddress.ToString()); Console.WriteLine("toAddress:\t" + toAddress.ToString()); Console.WriteLine("amountWei:\t" + amountWei.ToString()); Console.WriteLine("extraData:\t" + extraData.ToString()); Console.WriteLine("extraDataHex:\t" + extraDataHex.ToString()); Console.WriteLine("sendTxHash:\t" + sendTxHash.ToString()); return(sendTxHash); }
public async Task <Oath> GetOath(string txHash) { var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txHash).ConfigureAwait(false); Oath oath = new Models.Oath(); if (receipt != null) { oath.BlockHash = receipt.BlockHash; oath.BlockHeight = (int)receipt.BlockNumber.Value; HexUTF8String str = HexUTF8String.CreateFromHex(receipt.Logs.First.Value <string>("data").Substring(130)); oath.OathContent = str.Value.Replace("\0", ""); oath.TxHash = receipt.TransactionHash; } else { oath.TxHash = txHash; } return(oath); }
public RpcRequest BuildRequest(HexUTF8String valueToConvert, object id = null) { return(base.BuildRequest(id, valueToConvert)); }
public async Task <string> SendRequestAsync(HexUTF8String valueToConvertHexUtf8, object id = null) { return(await base.SendRequestAsync(id, valueToConvertHexUtf8).ConfigureAwait(false)); }
public Task <string> SendRequestAsync(HexUTF8String valueToConvertHexUtf8, object id = null) { return(base.SendRequestAsync(id, valueToConvertHexUtf8)); }
public Task <string> SendRequestAsync(HexUTF8String valueToConvertHexUtf8, object id = null, CancellationToken cancellationToken = default(CancellationToken)) { return(base.SendRequestAsync(id, cancellationToken, valueToConvertHexUtf8)); }