我想知道是否有可能侦听MakerDAO的LogNote事件,就像我们能够处理标准事件一样。
我所做的研究:
我从合同细节中看到LogNote被列为事件
let contractIntanse = await new web3.eth.Contract(abi, contractAddress);
console.log("contractIntanse.events: ", contractIntanse.events)
contractIntanse.events: {
Approval: [Function: bound ],
'0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925': [Function: bound ],
'Approval(address,address,uint256)': [Function: bound ],
LogNote: [Function: bound ],
'0xd3d8bec38a91a5f4411247483bc030a174e77cda9c0351924c759f41453aa5e8': [Function: bound ],
'LogNote(bytes4,address,bytes32,bytes32,bytes)': [Function: bound ],
Transfer: [Function: bound ],
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef': [Function: bound ],
'Transfer(address,address,uint256)': [Function: bound ],
allEvents: [Function: bound ]
}然而,我无法正确地检查这一点,例如:
1. event.watch不适合我,因为web3 v1
web3.eth.subscribe("logs", { address: "0x23..." },
function(error, result) {
console.log("subscribe result:",result);
console.log("subscribe error:",error);
})
.on("connected", function(subscriptionId) {
console.log("subscriptionId:" + subscriptionId);
})
.on("data", function(log) {
console.log("data:" + log);
})
.on("changed", function(log) {
console.log("changed:" + log);
});然而,当我触发事件时,我无法看到smth。
await contractIntanse.methods.rely(address1);下面是我设法找到https://github.com/ethereum/web3.js/issues/1752的相关问题
3.我还尝试使用getPastEvents,就像最新的issues/1752建议的那样
const eventOptions = { filter: {}, fromBlock: 0, toBlock: 'latest' };
const events = await contractIntanse.getPastEvents('LogNote', eventOptions);对于标准件事件,它可以正常工作。但是,对于LogNote,我得到了一个错误:
Error: overflow (operation="setValue", fault="overflow", details="Number can only safely store up to 53 bits")最后,我很困惑,我们能不能听MakerDAO的LogNote呢?感谢您的帮助,链接到文档,讨论等。谢谢!
我在用DAI合同https://etherscan.io/address/0x6b175474e89094c44da98b954eedeac495271d0f#contracts
这里是一个commit,用于在mainnet上进行部署。我曾作为基地。https://github.com/makerdao/dss/blob/6fa55812a5fcfcfa325ad4d9a4d0ca4033c38cab/src/dai.sol
LogNote是从LibNote那里获得的。这就是我想听的。https://github.com/makerdao/dss/blob/6fa55812a5fcfcfa325ad4d9a4d0ca4033c38cab/src/lib.sol
发布于 2020-07-24 14:09:24
因为LogNote是一个匿名事件,它比较便宜,但另一方面,您不能使用主题过滤它。有关更多详细信息,请参阅这已经回答了问题。。
无论如何,您可以监听所有契约事件,然后在Javascript中进行筛选。实际上,戴只有3种类型的事件:Transfer和Approval (有3个参数)和LogNote (4个参数)。LogNote只由rely和deny函数触发,因此您可以使用下面的代码侦听这些事件:
const Web3 = require("web3");
const web3 = new Web3("ws://localhost:8546");
web3.eth.subscribe("logs", {
address: "0x731830527c286469E89b5e43030C1fA3D9d78f03"
},
function (error, result) {
if (error) {
console.error("subscribe error:", error);
return;
}
if (result.topics.length == 4) {
// This is a `rely` or `deny` event
let signature = result.topics[0];
let sender = result.topics[1];
let arg1 = result.topics[2];
let arg2 = result.topics[3]; //this is always 0x0
}
})
.on("connected", function (subscriptionId) {
console.log("subscriptionId:" + subscriptionId);
});请注意,您不能区别于只查看日志的rely或deny,但必须检查原始事务有效负载。
https://ethereum.stackexchange.com/questions/85235
复制相似问题