public async Task <string> GetTransactionForSigning(EthTransaction ethTransaction, bool useTxPool = false) { string from = ethTransaction.FromAddress; var gas = new Nethereum.Hex.HexTypes.HexBigInteger(ethTransaction.GasAmount); var gasPrice = new Nethereum.Hex.HexTypes.HexBigInteger(ethTransaction.GasPrice); var nonce = await _nonceCalculator.GetNonceAsync(from, useTxPool); var to = ethTransaction.ToAddress; var value = new Nethereum.Hex.HexTypes.HexBigInteger(ethTransaction.Value); var tr = new Nethereum.Signer.Transaction(to, value, nonce, gasPrice, gas); var hex = tr.GetRLPEncoded().ToHex(); return(hex); }
private async Task <string> SendTransactionAsync(string from, string to, string data, BigInteger value, BigInteger?gasPrice, BigInteger?gasValue) { from = from == Constants.AddressForRoundRobinTransactionSending ? await _transactionRouter.GetNextSenderAddressAsync() : from; var semaphore = _semaphores.GetOrAdd(from, f => new SemaphoreSlim(1, 1)); try { await semaphore.WaitAsync(); (gasPrice, gasValue) = await GetGasPriceAndValueAsync(gasPrice, gasValue); var nonce = await _nonceCalculator.GetNonceAsync(from, true); var transaction = new Nethereum.Signer.Transaction(to, value, nonce.Value, gasPrice.Value, gasValue.Value, data); var signRequest = new EthereumTransactionSignRequest { FromProperty = new AddressUtil().ConvertToChecksumAddress(from), Transaction = transaction.GetRLPEncoded().ToHex() }; var signResponse = await _signingApi.ApiEthereumSignPostAsync(signRequest); var txHash = await _sendRawTransaction.SendRequestAsync(signResponse.SignedTransaction.EnsureHexPrefix()); return(txHash); } finally { semaphore.Release(); } }
public async Task <string> GetTransferTransactionRaw(Erc20Transaction erc20Transaction, bool useTxPool = false) { Contract contract = GetContract(erc20Transaction.TokenAddress); Function transferFunction = contract.GetFunction("transfer"); string functionDataEncoded = transferFunction.GetData(erc20Transaction.ToAddress, erc20Transaction.TokenAmount); BigInteger nonce = await _nonceCalculator.GetNonceAsync(erc20Transaction.FromAddress, useTxPool); var transaction = CreateTransactionInput(functionDataEncoded, erc20Transaction.TokenAddress, erc20Transaction.FromAddress, erc20Transaction.GasAmount, erc20Transaction.GasPrice, nonce, 0); string raw = transaction.GetRLPEncoded().ToHex(); return(raw); }