Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

No events captured #841

Closed
perbergman opened this issue Oct 26, 2022 · 11 comments
Closed

No events captured #841

perbergman opened this issue Oct 26, 2022 · 11 comments
Assignees

Comments

@perbergman
Copy link

[Ethereum events]

I am trying to use standard Ethereum event subscriptions, but I don't see any events.
Is this not supported?

Description

`const Web3 = require('web3');
const delay = time => new Promise(res=>setTimeout(res,time));
const WEB3_PROVIDER = 'ws://:10002/ws';

const web3 = new Web3(WEB3_PROVIDER);
const address = '0x';

async function main() {
console.log(1);
let x = await web3.eth.subscribe('logs', {
address: address,
topics: [
web3.utils.sha3("Transfer(address,address,uint256)")
]
}, (error, result) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
console.log(x);
await delay(5*60000);
console.log(3);
}

main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
`

Your environment

  • OS and version
    Server runs ubuntu 22.04.

  • version of the Polygon Edge
    0.5.0

  • branch that causes this issue
    Release

Steps to reproduce

Start the nodes.
Deploy the contract.
Start the event listener (above).
Run a test case operating the contract.

Expected behaviour

To see events being logged.

Actual behaviour

No events appear.

@laviniat1996
Copy link
Contributor

@perbergman Can you check the deployment of the contract with getCode: https://wiki.polygon.technology/docs/edge/get-started/json-rpc-commands#eth_getcode ?

@laviniat1996 laviniat1996 self-assigned this Oct 27, 2022
@perbergman
Copy link
Author

curl http://:10002 -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0x7d75a8C6531b38a93A3B9A47b03aB6dA715831e4", "latest"],"id":1}' > out.txt

out.txt

@perbergman
Copy link
Author

I can run transactions and see them in Block Scout, and with queries, but I don't see any events.
If I use --show-events with truffle, I get exceptions (doesn't happen with ganache, etc.).

BTW, I can't get it to work with hardhat at all, no big deal though.

@laviniat1996
Copy link
Contributor

@perbergman What happens when you start the event listener? Do you get any errors?
I just want to mention that we do support this, and I tested it today on my end.

Can you try using it with const WEB3_PROVIDER = 'ws://localhost:10002/ws' ?

@perbergman
Copy link
Author

I started it with the 'ws' and I don't see any errors, no output at all.

Seems my paste removed stuff, the URL is const WEB3_PROVIDER = 'ws://x.y.x:10002/ws';

I am running remotely from macOS --> AWS/ubuntu.

@perbergman
Copy link
Author

I don't see an eth_subscribe command in that list above, but there is eth_unsubscribe?

@laviniat1996
Copy link
Contributor

Hi @perbergman ,

I'm back with updates. Your event subscription script actually works.
The steps I followed for testing:

  1. Create a .js file with your code (let's call it listener.js)
  2. Started a local chain
  3. Created a dummy contract to test the script:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.5.0;
contract Test {
   event Transfer(address,address,uint256);
   function emitEvent() public payable {      
      emit Transfer(msg.sender,msg.sender,5000);
   }
}
  1. Deployed the contract with Remix
  2. I changed the contract address in the script
  3. Ran the script (node listener.js - makes sure to install all js dependencies)
  4. Triggered an event

image

@perbergman
Copy link
Author

perbergman commented Oct 28, 2022

I will try that. The issue might be that we deploy to a remote chain and networking etc. I am running a four-node Polygon Edge network with remote clients.

I will try to run the listener locally as well. I wonder if it has to do with the naming of the topic as well. We are using ERC1155.

@perbergman
Copy link
Author

I am running the Test contract remote with a listener locally, and now I see those events.
Next is to use my actual contracts.

Thanks,
Per

@perbergman
Copy link
Author

I got it to work all the way. The difference was when I did not use Truffle to deploy, but straight web3.

@laviniat1996
Copy link
Contributor

Hi @perbergman ,

Thank you for your updates. I'm glad it finally worked. Please feel free to open an issue whenever there's need.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants