Closed onbjerg closed 6 years ago
I am using web3 1.0.0 and I have somewhat the same problem. I did some test with this simple contract (using testrpc as the rpc provider) :
contract eventc {
event Top(string yolo);
function event_testing(string test){
Top(test);
}
}
contract_event.methods.event_testing("tessssst").send({from: address_pers,gas: 1500000,
gasPrice: 15000000}).then(console.log);
contract_event.events.Top({
fromBlock: 0,
toBlock: 'latest'
}, function(error, event){
console.log("event : ",event);
});
The console only return : event : null
(with the method transaction) despite multiple events in the blockchain.
As for me the getPastEvents
works fine.
Hello,
Same for me, getPastEvents
works allEvents
does not.
The following code raises:
const eventHandler = clientReceipt.events.allEvents((error, event) => {
if(error) {
throw error
}
console.log('Event:');
console.log(event);
});
Error: Returned error: Method not found
at Object.ErrorResponse (/home/vagrant/app/node_modules/web3/packages/web3-core-helpers/src/errors.js:29:16)
at Object.<anonymous> (/home/vagrant/app/node_modules/web3/packages/web3-core-requestmanager/src/index.js:137:36)
at callback (/home/vagrant/app/node_modules/web3/packages/web3-providers-ipc/src/index.js:65:40)
at Array.forEach (<anonymous>)
at Socket.<anonymous> (/home/vagrant/app/node_modules/web3/packages/web3-providers-ipc/src/index.js:76:51)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at addChunk (_stream_readable.js:266:12)
at readableAddChunk (_stream_readable.js:253:11)
at Socket.Readable.push (_stream_readable.js:211:10)
at Pipe.onread (net.js:585:20)
Versions:
Also having this issue, getPastEvents()
works like a dream but allEvents()
and consequently contract.events.Event()
do not work as expected.
They do not poll but will return an (unreliable) result under very specific circumstances as outlined below...
fromBlock
argument is specified as the current block
fromBlock
, different results are returned for each, and sometimes nothing is returned. The results are definitely not reliable. Once there's a new block, refreshing will return no results (assuming you have set fromBlock
statically). It will not however watch new events no matter how much you beg, yell or throw milkshakes at your computerIt should be noted that passing {}
as an argument doesn't seem to return any result unlike the above edge case, despite being noted in the documentation that the arguments are optional.
It's possible the aforementioned edge case may shed light on the source of this problem, sans the milkshake
I've tried both WS and IPC transport with similar results.
same story with: web3.eth.subscribe
;(
I subscribed to the event but it was not working. The callback was never called. Then I found out that I needed to activate the WebSockets server (--ws and similar in geth). Found it in this Ethereum Stack Exchange Post
Issuing the same problem with 1.0.0-beta.24
When trying to in nodejs script
contract.events.allEvents({ fromBlock: 'latest' })
.on('data', console.log)
.on('changed', console.log)
.on('error', console.log)
Nothing happens, script doesn't log anything and just exits while expecting it to hang and listen to the events, when I change code to this:
contract.events.allEvents({ fromBlock: 'latest' }, console.log)
Getting the error
Error: The current provider doesn't support subscriptions: HttpProvider
Connecting to local json rpc client
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
which launched with following params
geth --rpcapi "db,eth,net,web3,personal,web3" --rpc --rpcaddr "localhost" --rpcport "8545" --rpccorsdomain "*" --identity "MyTestNode" --datadir "./data" --testnet --fast
Tested with websocket providers - everything works fine
@Oxyaction could you please share the full code snippet, can't make it work either.
@alexey-ernest started geth node with:
geth --rpcapi "db,eth,net,web3,personal" --ws --wsaddr "localhost" --wsport "8545" --wsorigins "*" --identity "MyTestNode" --datadir "./data" --testnet --fast
connected to web3:
const web3 = new Web3(new Web3.providers.WebsocketProvider('http://127.0.0.1:8545'));
listening:
contract.events.allEvents({ fromBlock: 'latest' }, console.log)
I can't use webSokets. How I can catch contract events? web3 - version 1.0.0-beta23
@AndreyPatseiko Suppose it is impossible by it's nature, event should be initiated by the server and it is impossible with plain http protocol
You right. I was angry because about it any single word in the web3 documentation. Thanks for you example - if use webSocets all work correct, like as described in web3 documentation.
Anyone having a problem with watch all events not working after about 10 minutes?
Works if "latest" is used as fromBlock param, but does not work here if the fromBlock is different from latest.
Getting the following error:
Error: CONNECTION ERROR: Couldn't connect to node on IPC.
Was just exploring this same issue. Expanding @dskvr's observations, I wrapped my event listeners in a call to web3.eth.getBlock('latest') and explicitly pass the latest block number as fromBlock
. I'm doing this in docker w nodemon so it's been starting & restarting pretty wildly without any issues (so far). My setup looks something like:
web3.eth.getBlock('latest').then(res => {
console.log(`Starting event watchers from block ${res.number}`)
contract.events.allEvents({ fromBlock: res.number }, eventHandler)
})
Earlier I was debugging something similar and realized I only halfway enabled my websockets connection. Remember to specify websockets both while specifying the web3 provider ws://localhost:8546
and while starting geth --ws --wsorigins="*"
.
Same here using parity and web3 1.0.0-beta21
omg it is still not fixed since 2015 0_O
no, here is working
Sorry, forgot to close it. It works for me most of the time, but there are some things to keep in mind:
Happy hacking
To expand the comments by @onbjerg I also want to suggest one more troubleshooting tip for those who find themselves here:
See parity issue 6637 for details although it looks like this might have been fixed a couple days ago... Geth, on the other hand, has always been extremely reliable while fetching historical events.
Eth is straight garbage, I think. I am using websocket provider, but my web3 side hears ZERO events being emitted in my smart contract deployed on polygon Mumbai... wtf? 🤔
Using
allEvents
in Web3 1.0.0 does not return any events. My code is as follows:Using
getPastEvents
works. It seems like the subscription is never given an ID(?):I am using geth 1.6.7-stable.