1

用 ruby 的 eth.rb 出现了一个错误: insufficient funds for gas

 2 years ago
source link: https://www.v2ex.com/t/875818
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

用 ruby 的 eth.rb 出现了一个错误: insufficient funds for gas

  railsboy · 3 小时 32 分钟前 · 215 次点击

https://github.com/q9f/eth.rb

lib/eth/client.rb:485:in `send_command': insufficient funds for gas * price + value (IOError)

在网上搜没有找到解决方案,用 node 是可以的,但是不清楚是啥情况

12 条回复    2022-08-27 17:08:08 +08:00
railsboy

railsboy      3 小时 29 分钟前

调用
```
p client.transact_and_wait(controller, "setName", "123", '0xceA7F8364B4eB44c815514331e2d732AEA15b071',sender_key: key, legacy: true, gas_limit: 100000)
```

一直报错...
lovepplforever

lovepplforever      3 小时 24 分钟前

gas price 和 gas limit 设置有问题,或者说你的账户余额不足
railsboy

railsboy      3 小时 9 分钟前

@lovepplforever 你好,我想问下 gas price 和 gas limit 设置有什么规则吗,分别设置多少呢。余额是充足的,因为我在 typescript 里不用 ruby 的 sdk 是可以的,因为 ruby 的这个作者基本不太回复,所以只能自己看源码来解决问题..
wangshouh

wangshouh      3 小时 7 分钟前

如果 0xcEA7f8364b4eB44c815514331e2D732aEA15B071 这个是你的账户,在 moonscan.io 查询到你的账户中没有余额。
按照以太坊的标准而言,没有办法支付 gas 费用交易肯定失败。当然即使可以支付 gas ,如果你的 gas 设置错误,比如交易耗尽了 gas limit 但仍无法完成也可能造成错误。
如果你可以给出更详细的报错和交易哈希,可能会给出查找到原因
railsboy

railsboy      2 小时 58 分钟前

@wangshouh 嗨,谢谢你的回复,这是是我的账户:0xceA7F8364B4dB44c815514331e2d731eEA15b075 ,因为在执行过程过报错,所以没有生成 hash ,我可以提供下用 typescript 来写调用合约的代码生成的 hash: https://moonscan.io/tx/0x2b4e4767ae4d9d1a49f2d10458a534811c794a5c51bde0201be92416af8cef5b
railsboy

railsboy      2 小时 52 分钟前

https://moonscan.io/address/0xceA7F8364B4dB44c815514331e2d731eEA15b075 是成功的,所以我在想是不是 gas limit 和 git price 设置的问题,可能对于 ruby sdk 是有要求的,我该如何设置这两个值呢,不是太懂,谢谢解答
wangshouh

wangshouh      2 小时 40 分钟前

```
p client.transact_and_wait(controller, "setName", "123", '0xceA7F8364B4eB44c815514331e2d732AEA15b071',sender_key: key, legacy: true, gas_limit: 100000)
```
此代码说明你设置 gas_limit 为 100,000 gas
而查询这个合约操作需要 133,792 gas ,gas 不足所以失败。此处将 100000 设置为 133792 或者更高的数字可能成功。
具体可以参考一下我的博客 https://hugo.wongssh.cf/posts/ethereum-gas/
wangshouh

wangshouh      2 小时 38 分钟前   ❤️ 1

另,你此处使用的 gas 设置方法属于 legacy , 建议换成 EIP1559 ,具体参考我上文给出的博客
railsboy

railsboy      2 小时 19 分钟前

@wangshouh 好的,我看一下,谢谢
railsboy

railsboy      2 小时 8 分钟前

@wangshouh hi ,我刚刚尝试修改
```
'0xceA7F8364B4eB44c815514331e2d732AEA15b071',sender_key: key, legacy: true, gas_limit: 200000)
```
会报一样的错误,然后我又增加了
```
client.max_fee_per_gas = (270 * 1e9).to_i
p client.transact_and_wait(controller, "setName", "123",
```
是可以的,因为我看 tx 中的 Base Fee Per Gas:
是 0.0000001 GLMR (100 Gwei),虽然很模糊不太知道为什么。我会仔细再学习下你的文章,我成功的交易信息是: https://moonscan.io/tx/0xe4c04ee08ab53db4a6eece6018b1060a98a68a4a45920d1a65ae59c2758791df ,非常感谢你的帮助

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK