[英]Ethers.js: ReferenceError: utils is not defined
I'm trying to create a listener for incoming transactions with ethers.js (v5.6).我正在尝试使用 ethers.js (v5.6) 为传入事务创建一个侦听器。 According to the docs , to listen to incoming transactions you need to create this filter:
根据文档,要收听传入交易,您需要创建此过滤器:
// List all token transfers *to* myAddress:
filter = {
address: tokenAddress,
topics: [
utils.id("Transfer(address,address,uint256)"),
null,
hexZeroPad(myAddress, 32)
]
};
Having this in my script gives me an error saying utils.id("Transfer(address,address,uint256)"), ReferenceError: utils is not defined
.在我的脚本中有这个给我一个错误,说
utils.id("Transfer(address,address,uint256)"), ReferenceError: utils is not defined
。 I can't find anything in the docs about importing an utils package.我在文档中找不到任何关于导入 utils package 的内容。 Can anyone sort me out?
谁能帮我解决?
My full code:我的完整代码:
async function incomingTransactions() {
if (loadedUser) {
console.log("User loaded", loadedUser)
let myAddress = loadedUser.publicKey
let filter = {
address: myAddress,
topics: [
utils.id("Transfer(address,address,uint256)"),
null,
hexZeroPad(myAddress, 32)
]
};
// let foo = await provider.getLogs(filter)
// console.log(foo)
}
console.log("No user loaded")
}
const interval = setInterval(function() {
incomingTransactions();
}, 5000);
Looks like utils
is part of the ethers
object, and hexZeroPad
and id
are part of utils
so you can use them like so:看起来
utils
是ethers
object 的一部分,而hexZeroPad
和id
是utils
的一部分,因此您可以像这样使用它们:
const { ethers } = require("ethers"); // assuming commonjs
ethers.utils.id("Transfer(address,address,uint256)");
ethers.utils.hexZeroPad(myAddress, 32);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.