Esempio n. 1
0
        public static async Task <string> TransferAsync(Web3 web3, string contractAddress, string recipient, BigInteger amount, BigInteger gas, BigInteger gasPrice)
        {
            IContractTransactionHandler <TransferFunction> transferHandler = web3.Eth.GetContractTransactionHandler <TransferFunction>();

            var transfer = new TransferFunction()
            {
                To          = recipient,
                TokenAmount = amount,
                Gas         = gas,
                GasPrice    = Web3.Convert.ToWei(gasPrice, UnitConversion.EthUnit.Gwei)
            };

            TransactionReceipt transactionTransferReceipt = await transferHandler.SendRequestAndWaitForReceiptAsync(contractAddress, transfer).ConfigureAwait(false);

            return(transactionTransferReceipt.TransactionHash);
        }
Esempio n. 2
0
        public static async Task <string> TransferOfflineAsync(Web3 web3, string contractAddress, string recipient, BigInteger amount, HexBigInteger nonce, BigInteger gas, BigInteger gasPrice, string fromAddress = null)
        {
            IContractTransactionHandler <TransferFunction> transferHandler = web3.Eth.GetContractTransactionHandler <TransferFunction>();

            var transfer = new TransferFunction
            {
                To          = recipient,
                TokenAmount = amount,
                // Nethereum internally calls its Ethereum client by default to set the GasPrice, Nonce and estimate the Gas,
                // so if we want to sign the transaction for the contract completely offline we will need to set those values ourselves.
                Nonce    = nonce.Value,
                Gas      = gas,
                GasPrice = Web3.Convert.ToWei(gasPrice, UnitConversion.EthUnit.Gwei)
            };

            if (fromAddress != null)
            {
                transfer.FromAddress = fromAddress;
            }

            string result = await transferHandler.SignTransactionAsync(contractAddress, transfer).ConfigureAwait(false);

            return(result);
        }