Skip to content
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

web.eth.Contract support? #92

Closed
johnhforrest opened this issue Mar 17, 2018 · 6 comments
Closed

web.eth.Contract support? #92

johnhforrest opened this issue Mar 17, 2018 · 6 comments

Comments

@johnhforrest
Copy link

The documentation isn't clear to me so I this seemed like the next best place to look for an answer--please redirect me if there's a better place for me to ask.

We're using the web3.js 1.0 beta and creating a web3.eth.Contract object locally to interact with our contract.

I checked the /v1/jsonrpc/network/methods endpoint to see if getPastEvents is supported but it's currently not listed. However, I'm able to point to the Infura RPC endpoint and call getPastEvents just fine. My question is this: is this officially supported? Is there documentation that describes the web3.js 1.0 supported functions?

Here's a snippet of code. Currently we poll every 15s looking at (blockHeight - 12) to see if any events in our contract were in the block:

const events = await contractObject.getPastEvents('allEvents', {
      fromBlock: block.number,
      toBlock: block.number,
    })
@ec2
Copy link

ec2 commented Mar 19, 2018

The docs you were referring to is to our Rest endpoints. But yes, we do support that function in our websocket endpoints. We are in the process of making our docs better and that will be released soon. To my knowledge and please let me know if im wrong, but in Web3, the getPastEvents is just a wrapper around the getLogs RPC command, as there is no getPastEvents RPC command in the clients.

@ec2
Copy link

ec2 commented Mar 19, 2018

For Web3 1.0 docs, I'd just look at the official Web3 docs for that.

@johnhforrest
Copy link
Author

Thanks for the quick reply. You're right, I took a look at the web3.js source code and it's just a wrapper on getLogs, so that answers my original question.

To be clear, I'm not connecting to the websocket endpoint, just the HTTPS RPC endpoint sent in the original registration email. The only reference I found of the websocket endpoints was in #29 and not in any official documentation. Do you recommending connecting via websocket instead of RPC? If so, do you mind describing why and what the advantages are?

@ec2
Copy link

ec2 commented Mar 20, 2018

Ah. I'm not sure why I thought you were using the websocket endpoints haha.
I'd use the websocket endpoints if I were listening to events. The advantage is that you need not poll for new events. You will get em pushed to you instead.

@ec2
Copy link

ec2 commented Mar 20, 2018

The downside is that it is still in "experiemental" or beta mode right now and therefore there may be bugs.

@johnhforrest
Copy link
Author

No worries. Thanks for the info Eric!

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

No branches or pull requests

2 participants