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價格是多少?
uj5u.com熱心網友回復:
您的問題是 Fantom 是以太坊的一個分叉,尚未實施 EIP-1559 定價模型。為此,您必須提供 gas 價格(強制舊版)或在 web3.Eth.TransactionManager(舊版)中啟用它
如果未提供并且處于 Legacy 模式,Nethereum 會自動使用 eth_gasPrice 呼叫來設定 Gas Price。但是您應該向 Fantom 連鎖店查詢什么是獲得價格的最佳方式。
為什么需要傳遞chainId?這是簽署交易所必需的,并確保您知道您正在使用什么鏈。(防止輸入錯誤的 url 并獲得重放攻擊)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/491793.html
