nethereum-方法eth_feehistory不存在或不可用
我使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我有用的解决方案是禁用EIP1559交易。如果您使用的是启用了EIP1559的链条,最著名的是BSC,这将非常有用。这是这样做的代码:
希望这对将来的任何人都有相同的问题有所帮助。 (请注意,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:
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)
在Nethereum版本4.5中,方法
sendtransactionandwaitforreceiptasync
的逻辑已从3.8.0中实现的逻辑变化。因此,我不得不使用另一个功能覆盖。
这样,它将完全像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.
In this way, it will work exactly as the 3.8.0 of Nethereum.
只需使用此代码,就应该有效
web3.transactionmanager.uselegacyasdefault = true;
just use this code and should works
web3.TransactionManager.UseLegacyAsDefault = true;