COTI MetaMask Snap
Last updated
Was this helpful?
Last updated
Was this helpful?
The COTI MetaMask Snap allows users to onboard their COTI accounts, add/decrypt on-chain tokens and NFTs , and interact with COTI dApps.
As a user, you can start by installing the snap here:
Simply click the "Add to MetaMask" button on the upper right hand side of the screen and follow the prompts in your MetaMask wallet.
Once you click the "Connect" button, the prompt will go over the necessary permissions:
The snap will request the following permissions:
Access the internet: allows the snap to interact with any website that calls it to make a request (you must still approve requests made to it).
Display dialog windows in MetaMask: allows the snap to show MetaMask pop-ups with custom text, input fields, and buttons to approve or reject an action.
Display a custom screen: allows the snap to display a custom home screen in MetaMask. When clicking on menu >> snaps >> COTI, the custom screen is shown.
Store and manage its data on your device: allows the snap to store, update, and retrieve data securely with encryption. Only the COTI snap can access this information.
Access the Ethereum provider: allows the snap to communicate with MetaMask directly, in order for it to read data from the blockchain and suggest messages and transactions.
Use lifecycle hooks: allows the snap to use lifecycle hooks to run code at specific times during its lifecycle. Lifecycle hooks are actions that run when the snap is installed or updated, for example, when the snap is installed initially, it allows the confirmation screen to be shown.
Allow websites to communicate directly with COTI: allows websites/dApps to send messages to the COTI snap and receive a response from the COTI snap. All interactions must be user-approved.
Once the snap is installed, the MetaMask site will offer to continue to COTI's companion dApp website to get started with the snap.
Once you are in the companion dApp site (snap.coti.io):
Click on the "connect wallet" button, follow the prompts on MetaMask.
Once your account is onboarded:
Click the "Reveal AES Key" button to view your AES key.
Click the "Delete" button to delete your AES key.
NOTE: Your AES key should be treated with the same sensitivity as your MetaMask private key. Users who can obtain this key will be able to decrypt sensitive data on the COTI network.
If you are building a dApp on the COTI network and want it to interact with the COTI MetaMask snap, follow these steps:
Add @metamask/providers
to your dApp.
Create a function to detect if the user has Metamask to use it as a provider. You can guide yourself with this repo.
Create a MetaMaskProvider
in your dapp, which will let us know if COTI AES key manager is installed in the user's wallet. You can guide yourself with this repo.
Create the useRequest
hook to interact with Metamask. You can guide yourself with this repo.
Now, create a hook called useInvokeKeyManager
to invoke the COTI MetaMask Snap.
Optional - You can also create a hook that detects if COTI MetaMask Snap is installed or not.
Done! Now if you want to encrypt or decrypt some data from your dApp, you can use something like this:
To encrypt
To decrypt
Check the Metamask documentation for more information.
Click on the "Onboard account" button. The prompt will indicate the contract you are interacting with. Click the "Onboard" button. Follow the prompts on MetaMask. NOTE: Because the data from the onboarding operation is encrypted and MetaMask does not know how to decrypt this data, the "Signature request" screen in MetaMask will show illegible characters. This is normal.