0

Introduction

I'm developing a .NET 6 environment that has an API for transferring ether from one wallet to another wallet. It uses the Nethereum library for that.

Issue

I'm getting the Transaction Hash of the ether transfer. But when I'm trying to see it on Etherscan (see here) it doesn't appear. In addition to that, in my wallet, the value isn't transferred.

Workflow

The controller calls Transfer method, which calls TransferWaitingTxHashAsync method.

public bool Transfer(int ecommerceId, EtherWallet senderWallet, TransferRequestVO transferRequest)
    {
        string transactionHash = null;
        bool thrownError = false;
        try
        {
            transactionHash = _hdWalletManager.TransferWaitingTxHashAsync(senderWallet, transferRequest).Result;
        }
        catch (Exception)
        {
            thrownError = true;
        }

        if(thrownError || transactionHash == null) 
            return false;
        

        EthereumTransactionReceipt pendingTransactionReceipt = new()
        {
            From = senderWallet.Address,
            To = transferRequest.AddressDestination,
            EcommerceId = ecommerceId,
            TransactionHash = transactionHash,
            Status = EthereumTransactionReceiptAvailableStatus.Pending.Value
        };

        _ethereumTransactionReceiptRepository.Insert(pendingTransactionReceipt);
        bool saveChanges = _ethereumTransactionReceiptRepository.SaveChanges();

        return saveChanges;
    }

As you can see below, I'm doubling both Gas and GasPrice.

The Nonce is being summed to avoid transaction replacement underpriced (changing it on the debugger each time I run).

public Task<string> TransferWaitingTxHashAsync(EtherWallet senderWallet, TransferRequestVO transferRequest)
    {
        NethereumAccount senderAccount = new(senderWallet.PrivateKey);
        Web3 web3 = new(senderAccount, _httpAddress);

        HexBigInteger gasPrice = web3.Eth.GasPrice.SendRequestAsync().Result;
        decimal gasPriceDecimal = Math.Round(gasPrice.ToLong() * 2m);
        gasPriceDecimal = Web3.Convert.FromWei(BigInteger.Parse(gasPriceDecimal.ToString()), UnitConversion.EthUnit.Gwei);

        BigInteger gas = web3.Eth.GetEtherTransferService()
                                 .EstimateGasAsync(transferRequest.AddressDestination,
                                                   transferRequest.EtherAmount)
                                 .Result;

        gas = BigInteger.Add(gas, gas);

        BigInteger nonce = senderAccount.NonceService.GetNextNonceAsync().Result;
        BigInteger nextNonce = nonce + 131;


        return web3.Eth.GetEtherTransferService()
                       .TransferEtherAsync(transferRequest.AddressDestination,
                                           transferRequest.EtherAmount,
                                           gasPriceDecimal,
                                           gas,
                                           nextNonce);
    }

Environment

I'm running it locally using Infura as the provider (https://goerli.infura.io/v3/YOUR-API-KEY) for Goerli network.

Summarized

How can I fix it, and successfully complete my transaction or either see it on Etherscan (Goerli)?

0 Answers0