Ethereum Asked by Svitlana Moiseyenko on December 20, 2021
I wonder is there some possibility to listen MakerDAO’s LogNote events, like we able to do with standard events.
What I managed to research:
I saw that LogNote was listed as an event from contract details
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 ]
}
However, I was not able to check this properly, e.g:
1. event.watch does not work for me because of web3 v1
2. I tried using WebsocketProvider
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);
});
However, I was not able to see smth when I trigger event
await contractIntanse.methods.rely(address1);
Here is related issue I managed to find
https://github.com/ethereum/web3.js/issues/1752
3. I also tried to use getPastEvents, as latest issues/1752
suggested
const eventOptions = { filter: {}, fromBlock: 0, toBlock: 'latest' };
const events = await contractIntanse.getPastEvents('LogNote', eventOptions);
It works ok for standartd event. However, for LogNote I get an error:
Error: overflow (operation="setValue", fault="overflow", details="Number can only safely store up to 53 bits")
Eventually, I’m very confused, do we able to listen MakerDAO’s LogNote?
Appreciate any help, link to docs, discussions etc. Thanks!
ADDITIONAL:
I’m using DAI contract
https://etherscan.io/address/0x6b175474e89094c44da98b954eedeac495271d0f#contracts
Here is a commit was used for deployments on mainnet. I used as a base.
https://github.com/makerdao/dss/blob/6fa55812a5fcfcfa325ad4d9a4d0ca4033c38cab/src/dai.sol
The LogNote takes from LibNote. It what I’m trying to listen.
https://github.com/makerdao/dss/blob/6fa55812a5fcfcfa325ad4d9a4d0ca4033c38cab/src/lib.sol
Because LogNote
is an anonymous event it is cheaper but on the other side you cannot filter it using a topic. See this already answered question for more details.
Anyway, you can listen to all contract events and then filter in Javascript. DAI in fact has only 3 types of event: Transfer
and Approval
- with 3 parameters - and LogNote
- with 4 parameters. LogNote
is fired only by rely
and deny
functions, so you can use the code below to listen those events:
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);
});
Please note you cannot distinguish from rely
or deny
only looking at the log, but you must check the original transaction payload.
Answered by Giuseppe Bertone on December 20, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP