MetaMask / metamask-extension

:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites
https://metamask.io
Other
12k stars 4.91k forks source link

MetaMask web3 instance doesn't return events/logs #2393

Closed bwheeler96 closed 6 years ago

bwheeler96 commented 7 years ago

I can't get logs from my contract. The following code works fine with the default web3 implementation that comes with truffle:

contract.MeEvent({}, { fromBlock: 0 }).get((err, data) => console.log(data))

But when I run the same code in a browser using the MetaMask version of web3, nothing happens. The promise never returns, and nothing is ever even sent to the network.

For example in the truffle web3 instance, the following requests are logged by testrpc:

eth_newFilter
eth_getFilterLogs

But when using the MetaMask implementation, nothing is even submitted to the testrpc instance.

I read the compatibility guide and am following it pretty closely. I can send transactions and call contracts just fine. I simple can not filter events.

The web3 version MetaMask is injecting is 0.20.2 and the version that truffle builds with is 0.16.0. Hopefully web3 doesn't have any breaking changes in minor versions

nteymory commented 6 years ago

My mistake. In 3.13.3 changing networks still causes events to stop reporting for me as well. However, it does appear to sometimes work, whereas before it never used to work. I tried some tests based on the comments made by @ChainSafe and it doesn't seem to matter how long I wait before switching between networks. It could be that if you switch quickly, it's more likely to fail.

mattotodd commented 6 years ago

Just adding my 2 gwei to the conversation. I was not receiving contract events when using metamask, but events worked fine if i was connecting to local geth instance.

A) make sure your contract address is lower cased. (i'm assuming metamask is doing some filtering that uses your address and mine had upper case letters) B) close all chrome tabs, close chrome. Reopen chrome and log back in to metamask.

After I made those changes I am able to see events coming through. Still a bit flaky, but better than nothing.

m0wzer commented 6 years ago

Just spent half the day debugging why my DAPP frontend is not receiving events then found this issue. I can confirm this issue is still present in: 3.13.4

As already stated above, the following works as a solution - but hopefully we will get a fix:

  1. Switch to desired Network
  2. Close chrome and re-open
samid737 commented 6 years ago

I can confirm that this issue is present in 3.13.7, switching networks and restarting seems to help.

Noticeable, perhaps related:

Console.logging the contract event objects shows that arguments (including callbacks) passed through do not seem to be processed, but after doing the above they are.

before restart:

console.log(instance.setName({},{fromBlock: 0, toBlock: 'pending'},function(err,result){console.log(result)}));

c {requestManager: s, options: {…}, implementation: {…}, filterId: null, callbacks: Array(0), …} callbacks: [] filterId:"null" formatter: ƒ () getLogsCallbacks: [] implementation: {newFilter: ƒ, uninstallFilter: ƒ, getLogs: ƒ, poll: ƒ} options: {topics: Array(1). . .

after restart:

console.log(instance.setName({},{fromBlock: 0, toBlock: 'pending'},function(err,result){console.log(result)}));

c {requestManager: s, options: {…}, implementation: {…}, filterId: null, callbacks: Array(0), …} callbacks: [f] filterId:"0x3" formatter: ƒ () getLogsCallbacks: [] implementation: {newFilter: ƒ, uninstallFilter: ƒ, getLogs: ƒ, poll: ƒ} options: {topics: Array(1). . .

felzix commented 6 years ago

Is there a bug bounty or something on this? I'm willing to put in a few finney if it gets this fixed sooner.

gitcoinbot commented 6 years ago

This issue now has a funding of 0.25 ETH (217.57 USD) attached to it.

0xean commented 6 years ago

I just added some funding! hopefully someone can tackle this.

gitcoinbot commented 6 years ago

Work has been started on the 0.25 ETH (214.39 USD) funding by:

  1. @lazaridiscom

    Please work together and coordinate delivery of the issue scope. Gitcoin doesn't know enough about everyones skillsets / free time to say who should work on what, but we trust that the community is smart and well-intentioned enough to work together. As a general rule; if you start work first, youll be at the top of the above list ^^, and should have 'dibs' as long as you follow through.

    On the above list? Please leave a comment to let the funder (@pelsasser) and the other parties involved what you're working, with respect to this issue and your plans to resolve it. If you don't leave a comment, the funder may expire your submission at their discretion.

0xean commented 6 years ago

@lazaridiscom - yea, sorry my requirement doesn't really help alot since we would have to wait for this fix to make it into a new release. So I can remove that requirement so you can get paid in a timely fashion.

I can show you how to produce the error with our environment pretty easily - it is part of this issue here

Feel free to contact me phil@marketprotocol.io and I can help you get our development environment up to see the issue if you decide to go that route.

smarx commented 6 years ago

@lazaridiscom Glad to see you're trying to help here! Note that there are likely several bugs around events. The issue you just linked to looks different from what people are talking about here. The two main bugs I observed in this thread are:

  1. Events don't match if you use a mixed-case contract address. This has already been fixed. (See https://github.com/kumavis/eth-json-rpc-filters/issues/4).
  2. Events don't work if you switch networks. (I gave a "fix" in https://github.com/MetaMask/metamask-extension/issues/2393#issuecomment-351291768, but I suspect it's just hiding an underlying issue. It may, however, help you find a place to start.)

For a repro of the latter issue:

  1. Go to https://programtheblockchain.com/dapps/counter-with-events/ with MetaMask installed.
  2. Switch networks in MetaMask. It doesn't matter what network switch you do... just make sure you've switched and then ended up on Ropsten, since that's where the contract is deployed. (You can switch multiple times; the bug repros 100% once you've switched networks at least once.)
  3. Trigger an event by clicking the "Increment" button and note that no message is logged to indicate the event was observed.

To see the demo actually working properly, restart the browser (or disable/enable MetaMask) once you're on Ropsten and then don't switch networks after that. My repro works fine against ganache also, so you may want to deploy the same contract locally instead.

Contract source:

pragma solidity ^0.4.19;

contract Counter {
    uint256 public count = 0;

    event Increment(address who);   // declaring event

    function increment() public {
        Increment(msg.sender);      // logging event
        count += 1;
    }
}
nteymory commented 6 years ago

@lazaridiscom I tested your change (https://github.com/MetaMask/metamask-extension/pull/3224/files) and it appears to fix the problem on my end

gitcoinbot commented 6 years ago

Work for 0.25 ETH (214.25 USD) has been submitted .

If you are the claimee, please leave a comment to let the funder (@pelsasser) (and the other parties involved) that you've submitted you work. If you don't leave a comment, the funder may expire your submission at their discretion.

KennethAshley commented 6 years ago

@lazaridiscom Seems like your changes fixes this issue.

0xean commented 6 years ago

@lazaridiscom - thanks for the patience, releasing funding now.

gitcoinbot commented 6 years ago

The funding of 0.25 ETH (210.74 USD) attached to this issue has been approved & issued .