feat: add support for Metamask Starknet Snap #195
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theIStarknetWindowObject
interface.The
window.ethereum
object is searched in the current window, and if found, then astarknet_metamask
starknet wallet provider is embedded to the window object. This allows a dApp to use the metamask snap viastarknet_metamask
, which implements theIStarkentWindowObject
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:
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
http://localhost:5173/
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:
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.
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:
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.