7
排错:调用 parseLog 报 data out-of-bounds 错误
source link: https://blog.dteam.top/posts/2023-03/parselog-data-out-of-bounds.html
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.
排错:调用 parseLog 报 data out-of-bounds 错误
胡键 Posted at — Mar 16, 2023
阅读 9
调用 parseLog 解析日志,结果得到:
UnhandledPromiseRejectionWarning: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.6.0)
...
这种情况一般是使用的 abi 字符串与 contract 的实际 abi 不匹配:缺少了 indexed
关键字。如下例:
- 实际的 abi 为
event Transfer(address indexed from, address indexed to, uint256 indexed value)
- 但使用的却是:
event Transfer(address from, address to, uint256 value)
通过查看 log 的 topics 也能发现,topics 的内容实际是:event + indexed 参数,其长度可以反映出有多少个 indexed
参数。
很简单,补上缺失的 indexed
关键字即可。
觉得有帮助的话,不妨考虑购买付费文章来支持我们 🙂 :
付费文章Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK