trufflesuite / drizzle

Reactive Ethereum dapp UI suite
905 stars 235 forks source link

Replace injected web3 use with Provider. #14

Closed OnlyOneJMJQ closed 4 years ago

OnlyOneJMJQ commented 6 years ago
Mischi commented 6 years ago

We're building a mobile web app and would like to pass our version of web3 to Drizzle too.

Right now we're abusing the fact, that Drizzle will pass the provider from Metamask which we override to pass in our own provider.

Before we initialize Drizzle, we do the following:

// Override currentProvider from Mist/Metamask with our asure wallet for now
// This is picked up by drizzle.
window.web3 = {};
window.web3.currentProvider = new AsureWalletProvider();

Cheers, Fabian

Mischi commented 6 years ago

Hi. I'm thinking of providing a PR for this and wonder if you've already started to work on this issue? Also, can you explain a bit more what this ticket is about and what your expectations are? The more I think about this issue, the more I get the feeling that there is more than just providing my own web3 provider through the drizzleOptions.

Thanks you very much, Fabian

yahgwai commented 6 years ago

Hi @Mischi, @DiscRiskandBisque I've also found a need for this. I'm using multiple drizzle instances on the same page. To do this I've had to adjust the drizzle options to allow me to inject different web3 providers to each of the instance.

I'm not sure if this belongs in the drizzleoptions, as it feels nice to keep these static, but perhaps another arg to the drizzle constructor would work? I'm also happy to provide a PR.

OnlyOneJMJQ commented 5 years ago

We're currently working on this!

jklepatch commented 5 years ago

For development I tried to use my own web3 provider directly connected to ganache, to avoid having the Metamask modal annoying me:

  web3: {
    customProvider: new Web3.providers.HttpProvider('http://localhost:8545')
  },

Drizzle still showed me Metamask after this configuration. Is it related to this issue, or am I doing it wrong?

pklinger commented 5 years ago

Also can't get this running just like @jklepatch referenced. Can someone please elaborate how to pass in a HttpProvider via drizzleOptions correctly?

adrianmcli commented 5 years ago

To summarize:

It looks like the option of a customProvider has already been added. However, users are still having trouble passing in their own providers, as @jklepatch has mentioned above. @cds-amal can you take a look at this?

cds-amal commented 5 years ago

@jklepatch Sorry for the late response.

I'm not sure I understand the issue. Drizzle will use the custom provider if it's set in drizzleOptions. If a custom provider is not configured, it will try to see if metamask is injected in the browser and invoke window.ethereum.enable to pop the MM modal.

Do you have a repo that demonstrates your issue?

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

This issue has been closed, but can be re-opened if further comments indicate that the problem persists. Feel free to tag maintainers if there is no reply to further comments.

KorbinianK commented 5 years ago

@cds-amal Try the official drizzle-box. I just ran into the same issue, Metamask keeps popping up even though a custom provider is available. I added a customProvider in drizzleOptions.js as seen below:

const options = {
  web3: {
    block: false,
    customProvider: new Web3.providers.HttpProvider('http://localhost:8545'),
  },
  contracts: [SimpleStorage, ComplexStorage, TutorialToken],
  events: {
    SimpleStorage: ["StorageSet"],
  },
  polls: {
    accounts: 1500,
  },
};

How can I prevent this from happening?

jack0son commented 5 years ago

@KorbinianK I'm working on this same issue right now. I'll let you know if I find a solution.

adrianmcli commented 5 years ago

Let's re-open this for now. We are moving to a mono-repo soon and will probably move this issue over there.

OliveIT commented 4 years ago

I just faced the same issue and I'm super glad to see @cds-amal has made PR 1 hour ago. I wish @adrianmcli to approve this PR soon. BTW Is drizzle v1.5.0 officially released with web3js v1.2.1?

cds-amal commented 4 years ago

@OliveIT web3@"^1.2.1" was merged into develop and will be in the next release (soon).

kombos commented 3 years ago

guys, is this issue resolved? looks like it is still injecting Metamask by default, even when a blank drizzleOptions object is defined. There should be an option to prevent drizzle from injecting metamask provider by default. Or otherwise, there should be an option in which, if a customProvider is mentioned (even if a blank object is mentioned as customProvider), then drizzle should stop injecting metamask by default and go to fallback web3 instance.