trufflesuite / drizzle-utils

A library for interacting with Ethereum smart contracts based on RxJS streams.
MIT License
43 stars 15 forks source link

newBlockStream doesn't work with Infura #105

Closed honestbonsai closed 5 years ago

honestbonsai commented 5 years ago

The following code produces an error. Oddly it seems to work with const web3 = new Web3("http://127.0.0.1:9545");

Was doing it from inside get-balance-stream, so web3 version should be the same as the rest of the packages.

const web3 = new Web3("https://mainnet.infura.io/v3/KEY"); // HttpProvider
// track new blocks
const { observable } = createNewBlock$({
  web3,
  pollingInterval: 200, // only used if non-WebsocketProvider
});

observable.subscribe(console.log)
errors.js:29 Uncaught (in promise) Error: Returned error: invalid argument 0: hex string has length 6, want 64 for common.Hash
    at Object.ErrorResponse (errors.js:29)
    at index.js:125
    at XMLHttpRequest.request.onreadystatechange (index.js:103)
    at XMLHttpRequestEventTarget.dispatchEvent (xml-http-request-event-target.js:50)
    at XMLHttpRequest._setReadyState (xml-http-request.js:292)
    at XMLHttpRequest._onHttpResponseEnd (xml-http-request.js:463)
    at push../node_modules/stream-http/lib/response.js.exports.IncomingMessage.<anonymous> (xml-http-request.js:417)
    at push../node_modules/stream-http/lib/response.js.exports.IncomingMessage.push../node_modules/events/events.js.EventEmitter.emit (events.js:90)
    at endReadableNT (_stream_readable.js:1030)
    at afterTickTwo (index.js:31)
    at Item.push../node_modules/process/browser.js.Item.run (browser.js:167)
    at drainQueue (browser.js:131)
adrianmcli commented 5 years ago

Seems like the Web3 version we pinned ourselves to is having issues with Infura. There was another issue on this with the Drizzle repo I believe.

honestbonsai commented 5 years ago

Also, doesn't work in TFT, which is on "web3": "^1.0.0-beta.52". This web3 version works fine with Infura, but has issues with new-block-stream.

adrianmcli commented 5 years ago

Do you know if it's polling or subscribing? Might be an issue with eth-block-tracker that we use under the hood for polling?

honestbonsai commented 5 years ago

Infura was an https url, so it was polling I believe. Does Infura have a ws/wss endpoint?

Edit: yes https://infura.io/docs/gettingStarted/chooseaNetwork.md

and also does not work on wss Infura based on https://github.com/trufflesuite/drizzle-utils/issues/105#issue-443490472 code.

adrianmcli commented 5 years ago

@honestbonsai any ideas as to why this is failing? And we are certain that this is not a similar issue? https://github.com/trufflesuite/drizzle/issues/186

adrianmcli commented 5 years ago

This SO questions seems like it could be related: https://ethereum.stackexchange.com/questions/68180/signing-meesage-hex-string-has-length-64-want-40-for-common-address

In the mean time, do you think we can make a reproduction repo for this specific issue?

adrianmcli commented 5 years ago

Just to be clear, this is not related to MetaMask, correct?

honestbonsai commented 5 years ago

No wasn't using Metamask

honestbonsai commented 5 years ago

https://github.com/honestbonsai/du-infura-bug @adrianmcli reproduction repo.

  1. Put in your Infura key here https://github.com/honestbonsai/du-infura-bug/blob/master/src/bug.js#L4
  2. yarn start

Getting a different error now for some reason

web3-providers.umd.js:127 Uncaught (in promise) Error: Node error: {"code":-32600,"message":"invalid json request"}
    at Function.validate (web3-providers.umd.js:127)
    at HttpProvider._callee$ (web3-providers.umd.js:810)
    at tryCatch (runtime.js:45)
    at Generator.invoke [as _invoke] (runtime.js:264)
    at Generator.prototype.<computed> [as next] (runtime.js:98)
    at asyncGeneratorStep (asyncToGenerator.js:3)
    at _next (asyncToGenerator.js:25)
adrianmcli commented 5 years ago

Can you also put in a ganache version in parallel to show it working?

honestbonsai commented 5 years ago

Hmm having trouble getting it to work in Ganache as well. Anyways, I pushed it up.

honestbonsai commented 5 years ago

With web3 1.0.0-beta.35 (what drizzle-utils is pinned to) Ganache works (which is why the tests pass), but Infura does not.

ganache.js:11 GANACHE {number: 7, hash: "0x132e68ffdd4a175e1b947009ebd12e2a5f1d79692459858c8990ee4bc959ccfb", parentHash: "0x972da2a3cdfef76e1d84c3de127dd60a5e61547fe1f5fb49451704a2371fe546", mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000", nonce: "0x0000000000000000", …}
11:39:41.326 errors.js:29 Uncaught (in promise) Error: Returned error: invalid argument 0: hex string has length 6, want 64 for common.Hash
    at Object.ErrorResponse (errors.js:29)
    at index.js:125
    at XMLHttpRequest.request.onreadystatechange (index.js:83)
    at XMLHttpRequestEventTarget.dispatchEvent (xml-http-request-event-target.js:50)
    at XMLHttpRequest._setReadyState (xml-http-request.js:288)
    at XMLHttpRequest._onHttpResponseEnd (xml-http-request.js:459)
    at push../node_modules/stream-http/lib/response.js.exports.IncomingMessage.<anonymous> (xml-http-request.js:413)
    at push../node_modules/stream-http/lib/response.js.exports.IncomingMessage.emit (events.js:139)
    at endReadableNT (_stream_readable.js:1030)
    at afterTickTwo (index.js:31)
    at Item.push../node_modules/process/browser.js.Item.run (browser.js:167)
    at drainQueue (browser.js:131)
adrianmcli commented 5 years ago

@honestbonsai I've made a new reproduction repo that's a lot simpler (no need for React) here.

It looks like the problem lies with Eth-Block-Tracker and how it expects the provider to look/behave like. I've posted an issue on the Eth-Block-Tracker repo here: https://github.com/MetaMask/eth-block-tracker/issues/40