nethereum-方法eth_feehistory不存在或不可用

发布于 2025-02-03 12:36:24 字数 3602 浏览 5 评论 0原文

我使用Nethereum在区块链(虚拟机上的专用网络)上“写入”的函数。我被迫从3.8.0升级到版本4.5.0 在更新之前,一切正常,但是现在,当我调用sendtransactionandwaitforreceiptasync函数时,提出了以下异常。

Nethereum.JsonRpc.Client.RpcResponseException: the method eth_feeHistory does not exist/is not available: eth_feeHistory
   at Nethereum.JsonRpc.Client.ClientBase.HandleRpcError(RpcResponseMessage response, String reqMsg)
   at Nethereum.JsonRpc.Client.ClientBase.SendInnerRequestAsync[T](RpcRequestMessage reqMsg, String route)
   at Nethereum.JsonRpc.Client.ClientBase.SendRequestAsync[T](RpcRequest request, String route)
   at Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestFeesAsync()
   at Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestFeeAsync(Nullable`1 maxPriorityFeePerGas)
   at Nethereum.RPC.TransactionManagers.TransactionManagerBase.SetTransactionFeesOrPricingAsync(TransactionInput transaction)
   at Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignTransactionRetrievingNextNonceAsync(TransactionInput transaction)
   at Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignAndSendTransactionAsync(TransactionInput transaction)
   at Nethereum.RPC.TransactionReceipts.TransactionReceiptPollingService.SendRequestAndWaitForReceiptAsync(Func`1 transactionFunction, CancellationTokenSource tokenSource)
   at Project.BlockchainAdapter.BlockchainInteractionAdapter.Write(String privateKey, String contractAddress, String url, String smartContractLocation, String functionName, Object[] inputParameters, Int32 transactionValue, Int32 chainId)

那是代码:

public void Write(
      string privateKey,
      string contractAddress,
      string url,
      string smartContractLocation,
      string functionName,
      object[] inputParameters,
      int transactionValue = 0,
      int chainId = (int)Nethereum.Signer.Chain.Ropsten)
    {
      var function = GetEthFunction(privateKey, contractAddress, url, smartContractLocation, functionName, out Account account, chainId);

      var _transactionValue = new HexBigInteger(new BigInteger(transactionValue));
      var _estimatedGas = new HexBigInteger(new BigInteger(35000));
      try
      {
        _estimatedGas = function.EstimateGasAsync(
            account.Address,
            new HexBigInteger(new BigInteger(transactionValue)),
            new HexBigInteger(new BigInteger(transactionValue)),
            inputParameters).GetAwaiter().GetResult();
      }
      catch
      {
        // Intentionally left blank
      }

      var receipt = function.SendTransactionAndWaitForReceiptAsync(
            account.Address,
            _estimatedGas,
            _transactionValue,
            null,
            inputParameters).GetAwaiter().GetResult();
      if (!receipt.Status.Value.Equals(1))
      {
        throw new OperationCanceledException($"Unable to complete transaction. Transaction hash: {receipt.TransactionHash}.");
      }
    }
  }

private Function GetEthFunction(string privateKey,
      string contractAddress, string url, string smartContractLocation, string functionName, out Account account,
      int chainId)
    {
      account = new Account(privateKey, chainId);
      var web3 = new Web3(account, url);

      string abi = null;
      using (StreamReader file = File.OpenText($@"{smartContractLocation}"))
      {
        abi = file.ReadToEnd();
      }
      var contract = web3.Eth.GetContract(abi, contractAddress);
      return contract.GetFunction(functionName);
    }

我该如何解决? 谢谢。

I have a function that "write" on the blockchain (private network on a virtual machine), using Nethereum. I was forced to upgrade from version 3.8.0 to version 4.5.0
Before the update everything was working fine, but now, when i call the SendTransactionAndWaitForReceiptAsync function, the following exception is raised.

Nethereum.JsonRpc.Client.RpcResponseException: the method eth_feeHistory does not exist/is not available: eth_feeHistory
   at Nethereum.JsonRpc.Client.ClientBase.HandleRpcError(RpcResponseMessage response, String reqMsg)
   at Nethereum.JsonRpc.Client.ClientBase.SendInnerRequestAsync[T](RpcRequestMessage reqMsg, String route)
   at Nethereum.JsonRpc.Client.ClientBase.SendRequestAsync[T](RpcRequest request, String route)
   at Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestFeesAsync()
   at Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestFeeAsync(Nullable`1 maxPriorityFeePerGas)
   at Nethereum.RPC.TransactionManagers.TransactionManagerBase.SetTransactionFeesOrPricingAsync(TransactionInput transaction)
   at Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignTransactionRetrievingNextNonceAsync(TransactionInput transaction)
   at Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignAndSendTransactionAsync(TransactionInput transaction)
   at Nethereum.RPC.TransactionReceipts.TransactionReceiptPollingService.SendRequestAndWaitForReceiptAsync(Func`1 transactionFunction, CancellationTokenSource tokenSource)
   at Project.BlockchainAdapter.BlockchainInteractionAdapter.Write(String privateKey, String contractAddress, String url, String smartContractLocation, String functionName, Object[] inputParameters, Int32 transactionValue, Int32 chainId)

That is the code:

public void Write(
      string privateKey,
      string contractAddress,
      string url,
      string smartContractLocation,
      string functionName,
      object[] inputParameters,
      int transactionValue = 0,
      int chainId = (int)Nethereum.Signer.Chain.Ropsten)
    {
      var function = GetEthFunction(privateKey, contractAddress, url, smartContractLocation, functionName, out Account account, chainId);

      var _transactionValue = new HexBigInteger(new BigInteger(transactionValue));
      var _estimatedGas = new HexBigInteger(new BigInteger(35000));
      try
      {
        _estimatedGas = function.EstimateGasAsync(
            account.Address,
            new HexBigInteger(new BigInteger(transactionValue)),
            new HexBigInteger(new BigInteger(transactionValue)),
            inputParameters).GetAwaiter().GetResult();
      }
      catch
      {
        // Intentionally left blank
      }

      var receipt = function.SendTransactionAndWaitForReceiptAsync(
            account.Address,
            _estimatedGas,
            _transactionValue,
            null,
            inputParameters).GetAwaiter().GetResult();
      if (!receipt.Status.Value.Equals(1))
      {
        throw new OperationCanceledException(
quot;Unable to complete transaction. Transaction hash: {receipt.TransactionHash}.");
      }
    }
  }

private Function GetEthFunction(string privateKey,
      string contractAddress, string url, string smartContractLocation, string functionName, out Account account,
      int chainId)
    {
      account = new Account(privateKey, chainId);
      var web3 = new Web3(account, url);

      string abi = null;
      using (StreamReader file = File.OpenText($@"{smartContractLocation}"))
      {
        abi = file.ReadToEnd();
      }
      var contract = web3.Eth.GetContract(abi, contractAddress);
      return contract.GetFunction(functionName);
    }

How can I fix this?
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

∞梦里开花 2025-02-10 12:36:24

对我有用的解决方案是禁用EIP1559交易。如果您使用的是启用了EIP1559的链条,最著名的是BSC,这将非常有用。这是这样做的代码:

Web3.TransactionManager.UseLegacyAsDefault = true;

希望这对将来的任何人都有相同的问题有所帮助。 (请注意,Web3类必须在此处进行,并且不是 static)

A solution that worked for me is to disable EIP1559 transactions. This is very useful if you're using a non EIP1559 enabled chain, most notably BSC. Here is the code to do that:

Web3.TransactionManager.UseLegacyAsDefault = true;

Hope this helps anyone in the future with the same issue. (please note that the web3 class must be instanced here and is not static)

彻夜缠绵 2025-02-10 12:36:24

在Nethereum版本4.5中,方法sendtransactionandwaitforreceiptasync的逻辑已从3.8.0中实现的逻辑变化。
因此,我不得不使用另一个功能覆盖。

public void Write(...)
{
...
      var transactionInput = new TransactionInput
      {
        From = account.Address,
        Gas = _estimatedGas,
        MaxPriorityFeePerGas = null,
        GasPrice = _transactionValue,
        Type = null
      };
      var receipt = function.SendTransactionAndWaitForReceiptAsync(transactionInput, null, inputParameters).GetAwaiter().GetResult();
...
}

这样,它将完全像Nethereum的3.8.0一样工作。

In Nethereum version 4.5, the logic of the method SendTransactionAndWaitForReceiptAsync has changed from the one implemented in 3.8.0.
So, I had to use another function override.

public void Write(...)
{
...
      var transactionInput = new TransactionInput
      {
        From = account.Address,
        Gas = _estimatedGas,
        MaxPriorityFeePerGas = null,
        GasPrice = _transactionValue,
        Type = null
      };
      var receipt = function.SendTransactionAndWaitForReceiptAsync(transactionInput, null, inputParameters).GetAwaiter().GetResult();
...
}

In this way, it will work exactly as the 3.8.0 of Nethereum.

奢华的一滴泪 2025-02-10 12:36:24

只需使用此代码,就应该有效
web3.transactionmanager.uselegacyasdefault = true;

just use this code and should works
web3.TransactionManager.UseLegacyAsDefault = true;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文