RpcResponseException:不支持方法 eth_feeHistory。:使用 Ganache RPC 时的 eth_feeHistory

问题描述 投票:0回答:2

我正在尝试使用 .Net Core 构建一个 Web3 分布式应用程序。 对于测试和开发,我使用 Ganache 的专用网络。 当我尝试从 Netherium Web3 对象对已部署的智能合约进行函数调用时,如下所示:

var contractAddress = "0x5c2d640027901a19B94ee0f9EEFFdc1cB660898a";
var abi = @"[{""inputs"": [],""stateMutability"": ..... Complete ABI"; 
var contract = web3.Eth.GetContract(abi, contractAddress);
var getFunction = contract.GetFunction("getCount");
var addfunction = contract.GetFunction("addNewRecords");
            
// This is my account's address
var senderAddress = account.Address;

//this  works fine
var result_1 = await getFunction.CallAsync<int>();

// This Function Works fine
var gas = await addfunction.EstimateGasAsync(senderAddress, null, null, "Umer", "FAll2022", "[email protected]"); 
         
 //Here exception is thrown
 var result = await addfunction.SendTransactionAndWaitForReceiptAsync(senderAddress, gas, null, null, "Umer", "FAll2022", "[email protected]");

上面的代码抛出异常

RpcResponseException:不支持方法 eth_feeHistory。: eth_fee历史

请注意,当我调用如下查询函数时:

await getFunction.CallAsync<int>();

这会返回正确的结果,但调用应付函数会出现此类异常。

这是两个被调用函数的 Solidity 代码

function addNewRecords(string memory _name, string memory _email, string memory _rollNumber) public payable returns(bool) 
{
    // Increase the count by 1
    stdCount = stdCount + 1;

    // Fetch the student details
    // with the help of stdCount
    std_Records[int(stdCount)] = Student(_name,_email,_rollNumber);
    return true;
}

function getCount() public view returns(uint){
    return stdCount;
}

你能帮我一下吗?我正在添加完整的错误跟踪

RpcResponseException: Method eth_feeHistory not supported.: eth_feeHistory
Nethereum.JsonRpc.Client.ClientBase.HandleRpcError(RpcResponseMessage response, string reqMsg)
Nethereum.JsonRpc.Client.ClientBase.SendInnerRequestAsync<T>(RpcRequestMessage reqMsg, string route)
Nethereum.JsonRpc.Client.ClientBase.SendRequestAsync<T>(RpcRequest request, string route)
Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestFeesAsync()
Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestFeeAsync(Nullable<BigInteger> maxPriorityFeePerGas)
Nethereum.RPC.TransactionManagers.TransactionManagerBase.SetTransactionFeesOrPricingAsync(TransactionInput transaction)
Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignTransactionRetrievingNextNonceAsync(TransactionInput transaction)
Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignAndSendTransactionAsync(TransactionInput transaction)
Nethereum.Web3.Accounts.AccountSignerTransactionManager.SendTransactionAsync(TransactionInput transactionInput)
Nethereum.RPC.TransactionReceipts.TransactionReceiptPollingService.SendRequestAndWaitForReceiptAsync(Func<Task<string>> transactionFunction, CancellationToken cancellationToken)
BlockChainAppWeb.Controllers.HomeController.IndexAsync(Category c) in HomeController.cs
+
            var result_2 = await addfunction.SendTransactionAndWaitForReceiptAsync(senderAddress, gas, null, null, "Umer", "Farooq", "Abc");
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
System.Runtime.CompilerServices.ValueTaskAwaiter<TResult>.GetResult()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask<IActionResult> actionResultValueTask)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
c# asp.net-core smartcontracts web3js nethereum
2个回答
1
投票

我不知道你的具体逻辑,所以我参考官方文档搭建了一个基本的例子,你可以参考一下。

var url = "http://testchain.nethereum.com:8545";
var privateKey = "0x7580e7fb49df1c861f0050fae31c2224c6aba908e116b8da44ee8cd927b990b0";
var account = new Account(privateKey);
var web3 = new Web3(account, url);

var contractByteCode =
    "0x60606040526040516020806106f5833981016040528080519060200190919050505b80600160005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005081905550806000600050819055505b506106868061006f6000396000f360606040523615610074576000357c010000000000000000000000000000000000000000000000000000000090048063095ea7b31461008157806318160ddd146100b657806323b872dd146100d957806370a0823114610117578063a9059cbb14610143578063dd62ed3e1461017857610074565b61007f5b610002565b565b005b6100a060048080359060200190919080359060200190919050506101ad565b6040518082815260200191505060405180910390f35b6100c36004805050610674565b6040518082815260200191505060405180910390f35b6101016004808035906020019091908035906020019091908035906020019091905050610281565b6040518082815260200191505060405180910390f35b61012d600480803590602001909190505061048d565b6040518082815260200191505060405180910390f35b61016260048080359060200190919080359060200190919050506104cb565b6040518082815260200191505060405180910390f35b610197600480803590602001909190803590602001909190505061060b565b6040518082815260200191505060405180910390f35b600081600260005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060008573ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905061027b565b92915050565b600081600160005060008673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050541015801561031b575081600260005060008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505410155b80156103275750600082115b1561047c5781600160005060008573ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828282505401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a381600160005060008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282825054039250508190555081600260005060008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828282505403925050819055506001905061048656610485565b60009050610486565b5b9392505050565b6000600160005060008373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505490506104c6565b919050565b600081600160005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050541015801561050c5750600082115b156105fb5781600160005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282825054039250508190555081600160005060008573ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828282505401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905061060556610604565b60009050610605565b5b92915050565b6000600260005060008473ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060008373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005054905061066e565b92915050565b60006000600050549050610683565b9056";
var abi =
    @"[{""constant"":false,""inputs"":[{""name"":""_spender"",""type"":""address""},{""name"":""_value"",""type"":""uint256""}],""name"":""approve"",""outputs"":[{""name"":""success"",""type"":""bool""}],""type"":""function""},{""constant"":true,""inputs"":[],""name"":""totalSupply"",""outputs"":[{""name"":""supply"",""type"":""uint256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""_from"",""type"":""address""},{""name"":""_to"",""type"":""address""},{""name"":""_value"",""type"":""uint256""}],""name"":""transferFrom"",""outputs"":[{""name"":""success"",""type"":""bool""}],""type"":""function""},{""constant"":true,""inputs"":[{""name"":""_owner"",""type"":""address""}],""name"":""balanceOf"",""outputs"":[{""name"":""balance"",""type"":""uint256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""_to"",""type"":""address""},{""name"":""_value"",""type"":""uint256""}],""name"":""transfer"",""outputs"":[{""name"":""success"",""type"":""bool""}],""type"":""function""},{""constant"":true,""inputs"":[{""name"":""_owner"",""type"":""address""},{""name"":""_spender"",""type"":""address""}],""name"":""allowance"",""outputs"":[{""name"":""remaining"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""_initialAmount"",""type"":""uint256""}],""type"":""constructor""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""_from"",""type"":""address""},{""indexed"":true,""name"":""_to"",""type"":""address""},{""indexed"":false,""name"":""_value"",""type"":""uint256""}],""name"":""Transfer"",""type"":""event""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""_owner"",""type"":""address""},{""indexed"":true,""name"":""_spender"",""type"":""address""},{""indexed"":false,""name"":""_value"",""type"":""uint256""}],""name"":""Approval"",""type"":""event""}]";

var totalSupply = BigInteger.Parse("1000000000000000000");
var senderAddress = account.Address;

var estimateGas = await web3.Eth.DeployContract.EstimateGasAsync(abi, contractByteCode, senderAddress, totalSupply);

var receipt = await web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync(abi,
                contractByteCode, senderAddress, estimateGas, null, totalSupply);
Console.WriteLine("Contract deployed at address: " + receipt.ContractAddress);

var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);

var transferFunction = contract.GetFunction("transfer");
var balanceFunction = contract.GetFunction("balanceOf");
var newAddress = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe";

var balance = await balanceFunction.CallAsync<int>(newAddress);
Console.WriteLine($"Account {newAddress} balance: {balance}");
Console.WriteLine("Transfering 1000 tokens");
var amountToSend = 1000;

var gas = await transferFunction.EstimateGasAsync(senderAddress, null, null, newAddress, amountToSend);
var receiptAmountSend =
                await transferFunction.SendTransactionAndWaitForReceiptAsync(senderAddress, gas, null, null, newAddress,amountToSend);

balance = await balanceFunction.CallAsync<int>(newAddress);
Console.WriteLine($"Account {newAddress} balance: {balance}");

我的函数使用 C#:

[Function("balanceOf", "uint256")]
public class BalanceOfFunction : FunctionMessage
{
    [Parameter("address", "_owner", 1)]
    public string Owner { get; set; }
}

[Function("transfer", "bool")]
public class TransferFunction : FunctionMessage
{
    [Parameter("address", "_to", 1)]
    public string To { get; set; }

    [Parameter("uint256", "_value", 2)]
    public BigInteger TokenAmount { get; set; }
}

我的例子中没有出现这个问题。

另外,我看到其他帖子说要禁用EIP1559交易,你可以试试:

Web3.TransactionManager.UseLegacyAsDefault = true;

0
投票

在代码的交易构建部分指定gasPrice参数

© www.soinside.com 2019 - 2024. All rights reserved.