c# - Nethereum - 方法 eth_feeHistory 不存在或不可用

标签 c# .net-core nuget blockchain nethereum

我有一个使用 Nethereum 在区 block 链(虚拟机上的专用网络)上“写入”的功能。我被迫从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);
    }

我该如何解决这个问题? 谢谢。

最佳答案

对我有用的解决方案是禁用 EIP1559 事务。如果您使用非 EIP1559 启用的链(尤其是 BSC),这非常有用。这是执行此操作的代码:

Web3.TransactionManager.UseLegacyAsDefault = true;

希望这对将来遇到同样问题的人有所帮助。 (请注意,web3 类必须在此处实例化,并且不是静态的)

关于c# - Nethereum - 方法 eth_feeHistory 不存在或不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72462928/

相关文章:

c# - 为什么 System dll 在 Silverlight 和其他 C# 库中不同是有原因的

.net-core - Sentry 未在 .NET 中记录请求负载

c# - 使用 NuGet Pack 时是否可以在没有 nuspec 文件的情况下指定包名称?

asp.net-web-api - 在 .NET Framework 4.7.1 项目中安装 Microsoft.Extensions.DependencyInjection

jQuery 微调器箭头不可见

c# - 如何将数据从 asp.NET MVC 传递到 Angular2

c# - 如何使 boolean 值表现得像 'latch' ?

c# - 将基本搜索字符串转换为正则表达式

linux - 如何在 Linux 中的 dotnet core 中创建 GUI?

asp.net-core - 如何在 VS 2017 中更新 Microsoft.NETCore.App SDK 版本