为什么我不能用这个简单的代码发送 ftm

用户4951
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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么我不能用 Max date 加入这个查询?

为什么我不能用 lambda 替换这个函数

为什么我不能用 CSS 删除这个边框?

为什么我不能用 dev c 编译简单的项目

为什么我不能编译这个简单的线程测试?

为什么我不能将这个简单的 div 居中?

为什么我的代码不能访问这个变量?

为什么我不能用左值初始化这个 std::vector?

事件监听器为什么我不能用这个词

为什么这个模式不能用这个代码打开。它仍然重定向,但没有弹出模式

为什么我不能用链表::新?

为什么我不能用方法添加?

为什么我不能用pygame射击?

为什么这个 geojson 不能用 D3 渲染?

为什么这个https URL 不能用nodejs 查询?

为什么我不能用这段代码画一个椭圆呢?

为什么我不能用此C代码杀死进程组?

为什么这个简单的代码抛出NullPointerException?

为什么这个简单的代码抛出ArrayIndexOutOfBoundsException?

为什么这个 SQL 代码不能在 WHERE EXISTS 构造中使用简单的谓词?

为什么我不能用这个 CSS 为每个第二个元素设置样式?

在这个例子中,为什么我不能用函数的返回值代替函数名?

为什么我不能在JSFiddle中执行这个简单的JavaScript测试程序?

为什么我不能映射这个简单的对象以XML文本中的Java /新泽西?

为什么我不能启动这个简单的FXML hello world应用程序?

为什么我不能用 CSS 覆盖我的包装器?

为什么这段代码不能用 Numba 编译?

为什么此代码不能用于大量数字?

为什么此代码不能用作死锁?