-
Notifications
You must be signed in to change notification settings - Fork 12
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
How do I filter on events from contracts? #4
Comments
Also, what options do I have for the filters? How do options work? Could the examples be a bit more fleshed out? I love ETHJS other than that. |
@wahlforss thanks! Okay, so contract filtering is fairly straight forward and you can use it and learn more about it by using/viewing ethjs-contract. Module: API Example:
The contract object uses The filter code is available here, you can see we produce the solidity event SHA3 signature, that filter for it. https://github.com/ethjs/ethjs-contract/blob/master/src/index.js#L90-L99 Lastly, ethjs-filter does not work with stateless API's like the infura endpoint. But will work with extensions like metamask that polyfill the stateful API with a stateless version. We will soon address this by providing stateless API filtering, that does not require the node/endpoint to keep track of events. Thanks for use ETHJS! |
How do I listen to the event “NewBet” on my end?
Alfred Wahlforss
alfred@wahlforss.com
+46 70 587 21 61
… On 11 Dec 2017, at 18:58, Nick Dodson ***@***.***> wrote:
@wahlforss <https://github.com/wahlforss> thanks! Okay, so contract filtering is fairly straight forward and you can use it and learn more about it by using/viewing ethjs-contract.
Module:
https://github.com/ethjs/ethjs-contract <https://github.com/ethjs/ethjs-contract>
API Example:
const filter = simpleStore.SetComplete()
.new({ toBlock: 'latest' }, (error, result) => {
// result null <BigNumber ...> filterId
});
filter.watch((err, result) => {
// result null FilterResult {...}
});
filter.uninstall()
.then(result) => {
// result Boolean
});
The contract object uses ethjs-filter inside it.
The filter code is available here, you can see we produce the solidity event SHA3 signature, that filter for it.
https://github.com/ethjs/ethjs-contract/blob/master/src/index.js#L90-L99 <https://github.com/ethjs/ethjs-contract/blob/master/src/index.js#L90-L99>
Lastly, ethjs-filter does not work with stateless API's like the infura endpoint. But will work with extensions like metamask that polyfill the stateful API with a stateless version.
We will soon address this by providing stateless API filtering, that does not require the node/endpoint to keep track of events.
Thanks for use ETHJS!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#4 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAEeWZ4qzfuIeTagTL00wRLVO5IjgZtfks5s_W1hgaJpZM4Q9s6H>.
|
See the example above (similar to web3).
Example here using https://github.com/ethjs/ethjs-contract#usage and an example here using https://github.com/ethjs/ethjs#usage So it would be something like:
More examples here in the ethjs user-guide. https://github.com/ethjs/ethjs/blob/master/docs/user-guide.md#contract-instance |
Hello, On the other hand, I can do |
Let me look into this stat. I'll get back to you later today. Thanks!
…Sent from my iPhone
On Dec 18, 2017, at 8:03 AM, Louis ***@***.***> wrote:
Hello,
I can't make this example work either.
When I call myContract.Event().new() I get a Promise that resolves to the filter id.
On the promise object, there is no function watch: TypeError: filter.watch is not a function
On the other hand, I can do
let filter = myContract.Event().watch((err, res) => { console.log(res) })
But the events are not captured, and filter.filterId is null.
Any idea?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
So it should be that you setup the event then watch.
So:
const someEvent = contract.Event();
someEvent.new()
someEvent.watch()
Try this format and let me know how it goes.
…Sent from my iPhone
On Dec 18, 2017, at 8:03 AM, Louis ***@***.***> wrote:
Hello,
I can't make this example work either.
When I call myContract.Event().new() I get a Promise that resolves to the filter id.
On the promise object, there is no function watch: TypeError: filter.watch is not a function
On the other hand, I can do
let filter = myContract.Event().watch((err, res) => { console.log(res) })
But the events are not captured, and filter.filterId is null.
Any idea?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@lgaroche @wahlforss did you manage to get things working here? |
Havent tried yet. Will do that soon.
… On 20 Dec 2017, at 20:17, Nick Dodson ***@***.***> wrote:
.
|
Hey @SilentCicero Same issue here. "filter.watch is not a function" It also says
|
@SilentCicero the above mentioned format works
Though I saw 2 things unidentical:
|
That could be easily fixed, would you like to make a pr to address it?
…Sent from my iPhone
On Apr 17, 2018, at 11:35 PM, gasolin ***@***.***> wrote:
@SilentCicero the above mentioned format works
const someEvent = contract.Event();
someEvent.new()
someEvent.watch((err, result) => {
if(result[0]) {
// do something
}
});
Though I saw 2 things unidentical:
it's the callback, not a promise
the event watch keeping update every seconds with empty result, need extra filter(as above) for it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@SilentCicero I found Moving watcher.callback into |
Error: Invalid params: unknown field 'to', expected one of 'fromBlock', 'toBlock', 'address', 'topics', 'limit'.","code":-32603} i get this error too :< did the api change? seem like 'to' should be 'address' I made the RPC error go away like this but it seems I cant watch for events (watch callback is never called)
|
* devDeps: ganache-core@2.1.0 -> ganache-cli@^6.12.2 Necessary to make tests pass
I've been trying for hours to listen to events from contracts. There is nothing in the docs on how it is done. Please tell me how.
ethjs-filter
Before opening a new issue, please take a moment to review our community guidelines to make the contribution process easy and effective for everyone involved.
Before opening a new issue, you may find an answer in already closed issues:
https://github.com/ethjs/ethjs-filter/issues?q=is%3Aissue+is%3Aclosed
Issue Type
Description
(Add images if possible)
Steps to reproduce
(Add link to a demo on https://jsfiddle.net or similar if possible)
Versions
The text was updated successfully, but these errors were encountered: