project-serum / sol-wallet-adapter

Other
185 stars 92 forks source link

Injected Interface Design #12

Open Zergity opened 3 years ago

Zergity commented 3 years ago

We need an injected interface design so dapps can interact with browser extension wallets (MathWallet, eDeFi, etc.)

Goals:

Ethereum dapps rely on a single injection point (window.ethereum) for wallet interaction. All wallet extensions (MetaMask, ezDeFi, etc.) must compete for the chance to get injected since there's only 1 extension is active at a time. This is very simple for dapp to use but dapp also doesn't know which wallet is used (for display).

Solution 1: single interface - single wallet (same with Ethereum with extra info)

Solution 2: single interface - multiple wallets

Solution 3: single dispatcher - multiple wallets

Please discuss.

Related PRs: #11 #8

ericfish commented 3 years ago

Some thoughts about this:

  1. Solution 1 is used in other blockchain such as Ethereum/Polkadot, so far there is not big complains from the user side.
  2. Finally it is still the user's choice, no matter the user choice the wallet from dapp front-end or user choice which browser extension to use. But solution 2 need more understanding and effort from dapp team side which may cause confusion.
  3. This conflict does not exist in mobile app wallet since each app has its own injection environment. But solution 2 need more understanding and effort from dapp team side to support different mobile wallet as well which may cause confusion.
Zergity commented 3 years ago

But solution 2 need more understanding and effort from dapp team side which may cause confusion.

Good point. I have added Solution 3 to address this.

ericfish commented 3 years ago

Solution 3 is better, but all inject wallets need to follow the rules:

  1. Do not overwrite window.solana, always check if this object exist or not
  2. Use different name
Zergity commented 3 years ago

I've updated #11 so the provider object can be passed directly to the constructor, so it works with any of the solutions above. Dapp code can use new Wallet('solet.io') or new Wallet(window.solana) or new Wallet(window.anything) as long as it's injected.

Civoremo commented 3 years ago

Been trying to use solflare extension wallet and receive error saying "provider parameter must be an injected provider or a URL string" when doing new Wallet(window.solflare). any hints on whats causing the issue? phantom and sollet work without issues, for coin98 wallet had to build a wrapper for it to work