Skip to content

Instantly share code, notes, and snippets.

@svetlanama
Last active July 24, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svetlanama/01e37938be6103f4c8b8acb8b20df31c to your computer and use it in GitHub Desktop.
Save svetlanama/01e37938be6103f4c8b8acb8b20df31c to your computer and use it in GitHub Desktop.
//NETWORK: RINKEBY
// Test code
it("listen LogNote event", async function() {
let doubleDAIToken = await DAIToken.deployed()
let res = await doubleDAIToken.rely(address);
console.log(" res: ", res)
})
//npm run truffle -- test ./test/TestLogNote.js --network rinkeby
// Node.js server code
```
let contractInstanseAddress = "0xabc...."
let web3 = new Web3(new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws/v3/<INFURA_KEY>'));
// you may print details
let contractInstanse = new web3.eth.Contract(daiABI, doublePitchTokenAddress);
console.log("contractIntanse.events: ", contractInstanse.events)
//listenins
web3.eth.subscribe("logs", {
address: contractInstanseAddress
},
function (error, result) {
if (error) {
console.error("subscribe error:", error);
return;
}
console.error("subscribe result:", result);
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);
})
.on("data", function(log) {
console.log("data:" + log);
})
.on("changed", function(log) {
console.log("changed:" + log);
})
```
/// Example of subscribe result:
```
{removed: false, logIndex: 1, transactionIndex: 2, transactionHash: "0x31de4.....", blockHash: "0xab5aa...", …}
address: "0x230..."
blockHash: "0xa..."
blockNumber: 1234567
data: "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e0rtgd4563h00000000000000000000000002fethdnrgca5afdbd2881dahj3804d938fjstba0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
id: "log_b84b77a3"
logIndex: 1
removed: false
topics: (4) ["0x65fae35e00000000000000000000000000000000000000000000000000000000",
"0x000000000000000000000000cabcd....",
"0x0000000000000000000000000949d....",
"0x0000000000000000000000000000000000000000000000000000000000000000"]
transactionHash: "0xqwegfthdbtjgu456ghjt5678thfgkt....."
transactionIndex: 2
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment