Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injected Interface Design #12

Open
Zergity opened this issue Nov 26, 2020 · 5 comments
Open

Injected Interface Design #12

Zergity opened this issue Nov 26, 2020 · 5 comments

Comments

@Zergity
Copy link

Zergity commented Nov 26, 2020

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

Goals:

  • Dapp should work with any browser extension, without knowing which is installed on the user browser.
  • It's a plus if dapp knows the name of the browser extension, but just for display, not functionality.

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)

  • Dapp uses the same window.solana for all wallet extensions. The name of the wallet can be queried in window.solana.name and window.solana.desc, but they're optional for both dapp and wallets.
  • Dapp UI will show only 1 entry for the injected wallet (since there's only 1 can active at a time), the name of the wallet can be queried from window.solana.name or just injected.

Solution 2: single interface - multiple wallets

  • Wallets inject into window.solana[walletname], and dapps can use any of the wallets in the array they preferred, using the same interface as the current window.solana. Or just select the first one if they don't care.
  • Dapp UI will show each wallet as an entry, and multiple wallets can be installed together.

Solution 3: single dispatcher - multiple wallets

  • window.solana is injected to be a dispatcher, so it can be used just like window.ethereum
  • window.solana.wallet[name] is injected by each extensions.
  • window.solana.selectWallet(name) tells the dispatcher to redirect all requests to window.solana.wallets[name]. If none is set, the first wallet will be used.
  • window.solana.getWallets() returns all injected wallets.

Please discuss.

Related PRs: #11 #8

@ericfish
Copy link

ericfish commented Nov 26, 2020

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
Copy link
Author

Zergity commented Nov 26, 2020

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
Copy link

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
Copy link
Author

Zergity commented Nov 27, 2020

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
Copy link

Civoremo commented Sep 6, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants