-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Listen to events #1
Comments
Thanks for the positive comments! MetaMask doesn't support web sockets right now but they're getting close. This means we can't watch these events by default yet. This guy had the same issue: For a hacky solution you can check out this thread: |
@creazy231 I did some digging around. The problem is with the connection to web3. The out-of-box solution connects to web3 using json-rpc over http. Since we need listen to event as they're emitted, we need to persist that connection, meaning a websocket endpoint is needed. This change needs to happen at https://github.com/Paperchain/nuxt-box/blob/master/src/plugins/web3.js web3.setProvider(new Web3.providers.WebsocketProvider('ws://localhost:8546'));
// or use infura
web3.setProvider(new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/_ws')); You can also use the local geth ipc, recommended as the most secure way. // Using the IPC provider in node.js
var net = require('net');
var web3 = new Web3('/Users/myuser/Library/Ethereum/geth.ipc', net); // mac os path I haven't tested the above code out yet. But if you do try it, please update us :) Hope this helps for now. |
@rahulrumalla thanks a lot for your accomplished answer. I successfully manage the events via websockets now doing the following: and to listen to events I created a separate instance with the following code: therewith Im able to listen to events like so:
|
@creazy231 Awesome, stuff! Thanks for giving us the update. :) |
@rahulrumalla no problem :) just took me half a day to figure out how to listen to events :D the reason why it took me so long was, that there are sooo many code examples out there showing working solutions with the OLD version of web3 and Im supposed to use the newest version hopefully I can help some people with my solution :) |
Hey there,
Im using the nuxt-box and Im very satisfied with it.
Now I want to listen to events my contract emits but I cant find any solution how to do this.
That's wat I tried without success:
Anyone here could give me a small example?
Thanks a lot :)
The text was updated successfully, but these errors were encountered: