Using Smart Wallet with Sign-In with Ethereum
This guide covers creating a new Sign-In with Ethereum template project that uses Smart Wallet.
This simple implementation is for demo purposes only and is not meant to be an example of a production app. A production app should: 1. Generate a random nonce for each message on the backend. 2. Check the nonce and verify the message signature on the backend as specified in EIP-4361. 3. Invalidate nonces on logout to prevent replay attacks through session duplication.
Create a project
Follow the Wagmi guide to set up a template project and connect a Smart Wallet.
Install dependencies
Create a new SIWE component
Prompt to sign and store signature
Wagmi’s signMessage
function will open the Smart Wallet popup to sign the message. The signature is stored in the component’s state.
Verify the message signature
For Smart Wallet, ERC-1271 should be used to verify the SIWE message signature.
This simple example does not check the nonce during verification, all production implementations should. Furthermore, nonces should be invalidated on logout to prevent replay attacks through session duplication (e.g. store expired nonce and make sure they can’t be used again). In production apps, SIWE message verification is generally handled on the backend.
Sign in with Ethereum
Visit your local server and click “Sign In with Ethereum”