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

feat: add support for Metamask Starknet Snap #195

Closed

Conversation

bajpai244
Copy link

@bajpai244 bajpai244 commented Oct 11, 2023

This is a draft PR, and it tries to throw some light on how we can integrate the metamask starknet snap with get-starknet, and allow to onboard metamask users directly to starknet dapps.

The PR contains the following:

MetaMask Snap Wrapper

There is a MetaMask Snap Wrapper, which takes the injected metamask provider { window.ethereum }, and exposes a new injected starknet wallet provider, which implements the IStarknetWindowObject interface.

The window.ethereum object is searched in the current window, and if found, then a starknet_metamask starknet wallet provider is embedded to the window object. This allows a dApp to use the metamask snap via starknet_metamask, which implements the IStarkentWindowObject interface { hence dApps can start using it without any changes required. }

Updated Example

The example has been updated in this draft PR, to allow someone to do:

  • an ERC20-transfer
  • message signing
  • and contract deployment from their MetaMask Wallet itself.

Demo

I am attaching a link of a working demo with this draft PR:

Link to demo.

How to check this out locally?

The following steps can be followed to play around with this POC locally:

  • git clone https://github.com/bajpai244/get-starknet.git
  • cd get-starknet
  • git checkout add-metamask-support
  • pnpm install
  • npm run dev
  • Open a browser { with MetaMask Installed }, go to http://localhost:5173/
  • then you can follow what the demo posted in the above section

If you need some tokens { you can use starknet faucet }, and want to see the balance of your account which is on the MetaMask Snap, then you can to the following website.

Pending Features

The following features are pending, we are in touch with the starknet-snap team to implement them, so that the MetaMask snap can be fully compatible with get-starknet api:

  • multicall {  as of now only one call per transaction is supported }, can be solved easily on the snap side
  • ability to declare contracts, can be solved easily on the snap side
  • ability to have multiple accounts, can be solved on the snap side
  • wallet events, hard to solve on the snap side, but polling can solve this
  • fee esitmations & transaction simulations, can be solved easily on the snap side

This draft and the associated demo are supposed to throw light on how the feature can be achieved + what it looks like on the user side, changes on the snap can enable seemless integration with get-starknet and create an overall win-win situation for the starknet ecosystem.

Appendix

This Appendix, throws some light on MetaMask Snap, their Impact, their limiation, and how the existing limitations can be overcomed.

About the MetaMask Starknet Snap


MetaMask Snaps are a powerful feature from MetaMask, this allows developers to create extensions { aka Snaps } for MetaMask, and allow these Snaps to interact with DApps via the MetaMask wallet.

Hence, MetaMask can then be extended to be used with blockchains which it doesn't support natively { we already have snaps for Starknet, Solana, Aptos, etc. }

The way dApp interacts with a snap, is by sending an RPC request to MetaMask via the injected provider, and then MetaMask forwards the request to relevant snap { each snap has a snapId for unique identification }.

The snap is then free to handle this request as it seems fit.

Pasted image 20231011135727

Snaps have the ability to derive new accounts from the MetaMask seed phrase, by doing a BIP-44, hence, in case of MetaMask snap, if someone has access to their MetaMask seed phrase, they can automatically recover their starknet accounts as well.

MetaMask has a snap available for the starknet network, it can do the following as of now:

  • manage accounts { account creation and deployment }
  • sign messages
  • send transactions
  • deploy contracts

MetaMask has a huge distribution, if the snap becomes very easy to use for every dApp in the ecosystem, it can smooth onboarding of new users to Starknet, where to interact with a Starknet dApp, they can directly start using MetaMask, rather than having the friction of firstly downloading a new wallet for the dApp.

Limitation of the MetaMask Snap


MetaMask snap as of now require to communicate via the window.ethereum injected metamask provider, which means all starknet dApps have to make changes to their existing codebases to be able to use snaps with their dApps.

MetaMask Snap meets GetStarknet


The industry standard as of now is to use wallets is via get-starknet, and if the starknet metamask snap is compatible with it, then all starknet DApps can start using the MetaMask snap without having to add any extra piece of code.

The way to achieve this should be to have a wrapper over Metamask injected provider, which exposes all standard starknet wallet APIs, so that all dApps can start using it.

Pasted image 20231011163553

@naorye2
Copy link
Contributor

naorye2 commented Mar 17, 2024

Handled here #208

@naorye2 naorye2 closed this Mar 17, 2024
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

Successfully merging this pull request may close these issues.

2 participants