Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nethereum.JsonRpc.Client.RpcResponseException : The field to must have byte length of 20: eth_estimateGas #1029

Closed
ranaabhishek172 opened this issue May 20, 2024 · 1 comment

Comments

@ranaabhishek172
Copy link

ranaabhishek172 commented May 20, 2024

Hi, I am getting this exception when trying to estimate gas for a transaction:

Message: 
Nethereum.JsonRpc.Client.RpcResponseException : The field to must have byte length of 20: eth_estimateGas

Stack Trace: 
ClientBase.HandleRpcError(RpcResponseMessage response, String reqMsg)
ClientBase.SendInnerRequestAsync[T](RpcRequestMessage reqMsg, String route)
ClientBase.SendRequestAsync[T](RpcRequest request, String route)
TestHelpers.Fund(SignerOrProvider signer, BigInteger amount, String fundingKey)
TestHelpers.FundL1(SignerOrProvider l1Signer, BigInteger amount)
CustomERC20Tests.SetupState()
CustomERC20Tests.SetUp()
GenericAdapter1.BlockUntilCompleted() NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter) AsyncToSyncAdapter.Await[TResult](Func1 invoke)
AsyncToSyncAdapter.Await(Func`1 invoke)
SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method)
SetUpTearDownItem.RunSetUp(TestExecutionContext context)
<>c__DisplayClass1_0.b__0()
DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

My code snippet:
`

        // Generate a new private key
        var privateKey = EthECKey.GenerateKey().GetPrivateKey();

        // Create a new account with the generated private key
        var signer = new Account(privateKey);

        // Initialize the Web3 instances with the signer account
        var provider = new Web3(signer, Config.ETH_URL);

        var wallet = new Account(Config.ETH_KEY);

        var tx = new TransactionInput
        {
            From = wallet.Address,
            To = signer.Address,
            Value = amount.ToHexBigInteger(),
            Nonce = await provider.Eth.Transactions.GetTransactionCount.SendRequestAsync(wallet.Address),
            GasPrice = await provider.Eth.GasPrice.SendRequestAsync(),
            ChainId = await provider.Eth.ChainId.SendRequestAsync(),
            MaxFeePerGas = new HexBigInteger(875000000),
        };

        var estimatedGas = await provider.Eth.TransactionManager.EstimateGasAsync(tx);

`
My signer.Address is "0xDAf8F18fd376Eb28457baa60B7B974a2A8423bb2CCF643Eb02bF68258cdBb7a2".
My ETH_URL is "http://localhost:8545"
I am using Nethereum.Web3 Version="4.19.0"
Nethereum.Accounts Version="4.19.0"
in a .net core 7.0 app.

@ranaabhishek172
Copy link
Author

Adding the Request Interceptor and updating the version to 4.20.0 resolved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant