I’m developing a dapp on the Internet Computer and want to implement MetaMask login functionality similar to OpenChat’s simple one-button approach. I need help with:
Current Goal
I need to connect MetaMask and obtain an identity that can be used with the Agent:
const agent = new HttpAgent({
identity: fetchIdentity(MetaMaskToken),
host,
});
Where my backend can catch that in caller()
What I’ve Tried
Looked at ic-swi example but found it overly complex, it requires user to preform two steps and I want them to do it in just one click
Tried to navigate OpenChat’s codebase but it’s quite large and difficult to extract just the MetaMask integration part
What I Need
A simpler implementation with a single button for MetaMask connection
The correct way to get the identity from MetaMask that works with HttpAgent
Ensure that caller() returns the MetaMask ID when the user is authenticated
?
Has anyone implemented a clean solution for this or can point me to relevant code examples? Ideally looking for something more straightforward than the existing examples.
It seems that the one most widely used in the community is the SIWE developed by Astrox.
I once developed an application that allowed users to log in using MetaMask. The flow was simple: the frontend would prompt MetaMask to sign a message (which could be customized), and after signing just once, users could log into the IC directly.
This mechanism uses a Delegation Identity flow similar to Internet Identity. It’s a bit complex to explain, but not too difficult to implement or use.
I didn’t package it as a public infrastructure library at the time, but I can show you how to implement the functionality you’re looking for—you’ll just need to adapt the code I provide. If you’re interested, I’d be happy to walk you through it.