Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim privatekey = System.IO.File.ReadAllText("privatekey.txt")
'Dim publickey = "0x898568c58466957bedaE0e2A2457beb158a150de" ''
Dim destination = "0x7fD0Ec4d9908A712852d32d110839Fc1A9Ce55d5"
Dim rpcURL = "https://rpc.ftm.tools" ' where should I put this
Dim chainID = 250 'Where should I put this?
Dim account = New Nethereum.Web3.Accounts.Account(privatekey, chainID)
Dim web3 = New Nethereum.Web3.Web3(account, rpcURL)
Dim amount = New Nethereum.Hex.HexTypes.HexBigInteger(10)
Await web3.TransactionManager.SendTransactionAsync(account.Address, destination, amount)
End Sub
我正在学习使用以太坊。
我做了这个简单的代码。简单的。我想将 10 wei 的 fantom 发送到另一个地址。简单对。
我收到了这个错误
这很奇怪。
索引超出了数组的范围?什么束缚?
无论如何,这是一个非常简单的程序。我想知道我哪里错了?
这是正确的方法吗?
其他与我们相关的小问题(我应该单独问这个)。为什么chainID是account的属性而rpcURL是web3的属性。我认为使用https://rpc.ftm.tools的 fantom 链使用 chainID 250。所以如果我们知道链 id,我们就知道 rpc url,如果我们知道 rpc url,我们就知道它会无论如何,只适用于一个链 ID。
如何修复我的代码?怎么了?如果有人能解释chainID rpcURL 的困境,那就太好了。
我进一步查看错误发生的位置。当 netthereum 尝试计算 gas 费用时,似乎会发生错误。
在
Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestFees(FeeHistoryResult feeHistory, BigInteger tip)
at Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.<SuggestFeesAsync>d__29.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.<SuggestFeeAsync>d__27.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Nethereum.RPC.TransactionManagers.TransactionManagerBase.<SetTransactionFeesOrPricingAsync>d__37.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Nethereum.Web3.Accounts.AccountSignerTransactionManager.<SignTransactionRetrievingNextNonceAsync>d__14.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Nethereum.Web3.Accounts.AccountSignerTransactionManager.<SignAndSendTransactionAsync>d__16.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Nethereum.RPC.TransactionReceipts.TransactionReceiptPollingService.<SendRequestAndWaitForReceiptAsync>d__5.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at testapp.Form1.VB$StateMachine_9_doSomething.MoveNext() in C:\Users\teguh\Dropbox\vb.net\testapp\testapp\Form1.vb:line 21
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at testapp.Form1.VB$StateMachine_8_Button1_Click.MoveNext() in C:\Users\teguh\Dropbox\vb.net\testapp\testapp\Form1.vb:line 3
无论如何,我打算手动执行此操作。但是我应该怎么做呢?
我将代码更改为
Dim privatekey = System.IO.File.ReadAllText("privatekey.txt")
'Dim publickey = "0x898568c58466957bedaE0e2A2457beb158a150de" ''
Dim destination = "0x7fD0Ec4d9908A712852d32d110839Fc1A9Ce55d5"
Dim rpcURL = "https://rpc.ftm.tools" ' where should I put this
Dim chainID = 250 'Where should I put this?
Dim account = New Nethereum.Web3.Accounts.Account(privatekey, chainID)
Dim web3Obj = New Nethereum.Web3.Web3(account, rpcURL)
'Dim amount = Nethereum.Web3.Web3.Convert.ToWei(0.1)
Dim balance = Await web3Obj.Eth.GetBalance.SendRequestAsync(account.Address)
Dim EtherBalance = Nethereum.Web3.Web3.Convert.FromWei(balance.Value) 'I got the correct value here
Dim result = Await web3Obj.Eth.GetEtherTransferService.TransferEtherAndWaitForReceiptAsync(destination, 1D, 1)
基本上,我是小气,说gas price应该是1wei。我“当之无愧地”收到了这条消息
交易被低估
我想我应该自己编码汽油价格。我该怎么做?fantom的最低gas价格是多少?
您的问题是 Fantom 是以太坊的一个分叉,尚未实施 EIP-1559 定价模型。为此,您必须提供 gas 价格(强制旧版)或在 web3.Eth.TransactionManager(旧版)中启用它
如果未提供并且处于 Legacy 模式,Nethereum 会自动使用 eth_gasPrice 调用来设置 Gas Price。但是您应该向 Fantom 连锁店查询什么是获得价格的最佳方式。
为什么需要传递chainId?这是签署交易所必需的,并确保您知道您正在使用什么链。(防止输入错误的 url 并获得重放攻击)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句