public static async Task <string> ConfirmTransactionAsync(Web3 web3, string contractAddress, BigInteger transactionId, BigInteger gas, BigInteger gasPrice)
        {
            IContractTransactionHandler <ConfirmTransactionFunction> confirmationHandler = web3.Eth.GetContractTransactionHandler <ConfirmTransactionFunction>();

            var confirmTransactionFunctionMessage = new ConfirmTransactionFunction()
            {
                TransactionId = transactionId,
                Gas           = gas,
                GasPrice      = Web3.Convert.ToWei(gasPrice, UnitConversion.EthUnit.Gwei)
            };

            TransactionReceipt confirmTransactionReceipt = await confirmationHandler.SendRequestAndWaitForReceiptAsync(contractAddress, confirmTransactionFunctionMessage).ConfigureAwait(false);

            return(confirmTransactionReceipt.TransactionHash);
        }
예제 #2
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);
        }
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <returns></returns>
        /// <exception cref="T:src.Contract.ContractException">Thrown if the transaction can not be completed</exception>
        public async Task ConfirmUpdate()
        {
            IContractTransactionHandler <ConfirmUpdateFunction> updateTxHandler = _web3.Eth.GetContractTransactionHandler <ConfirmUpdateFunction>();
            ConfirmUpdateFunction updateTx = new ConfirmUpdateFunction
            {
                FromAddress = _validatorAddress,
                Gas         = new BigInteger(500000)
            };

            TransactionReceipt confirmResponse = await updateTxHandler.SendRequestAndWaitForReceiptAsync(_ncContractAddress, updateTx);

            bool?hasErrors = confirmResponse.HasErrors();

            if (hasErrors.HasValue && hasErrors.Value)
            {
                throw new ContractException("Unable to confirm update");
            }
        }
예제 #4
0
        public async Task <MintNftResponse> Handle(MintNftRequest aMintNftRequest, CancellationToken aCancellationToken)
        {
            IContractTransactionHandler <MintNftRequest> contractTransactionHandler =
                Web3ContractManager.Web3.Eth.GetContractTransactionHandler <MintNftRequest>();

            HexBigInteger gasEstimate =
                await contractTransactionHandler.EstimateGasAsync(EthereumSettings.NftCreatorAddress, aMintNftRequest);

            aMintNftRequest.Gas = gasEstimate;
            TransactionReceipt transactionReceipt = await contractTransactionHandler
                                                    .SendRequestAndWaitForReceiptAsync(EthereumSettings.NftCreatorAddress, aMintNftRequest);

            List <EventLog <MintNftEventDto> > mintNftEventDtos = transactionReceipt.DecodeAllEvents <MintNftEventDto>();

            return(new MintNftResponse
            {
                MintNftEventDto = mintNftEventDtos.FirstOrDefault()?.Event,
                TransactionReceipt = transactionReceipt
            });
        }
예제 #5
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);
        }
예제 #6
0
 public static async Task <TransactionReceipt> asyncTransferAmount(string contractAddress, TransferFunction transfer, IContractTransactionHandler <TransferFunction> deploymentHandler)
 {
     return(await deploymentHandler.SendRequestAndWaitForReceiptAsync(contractAddress, transfer));
 }