ERC-4361 · Final · ERC · 2021-10-11
ERC-4361: Sign-In with Ethereum
Sign-In with Ethereum (SIWE): a standard plain-text message that a wallet signs to log in to a website, giving apps a self-custodial alternative to 'Sign in with Google'.
What problem does it solve?
Many dapps already let users "log in" by signing a message with their wallet, then set a session cookie. But every site invented its own message text. Wallets could not tell a login request apart from any other signature, users saw inconsistent prompts, and many implementations forgot basics such as replay protection or checking which site actually asked for the signature, which made phishing easy.
ERC-4361 standardises the message format and the checks both sides must do, so any wallet can recognise and safely display a login request, and any server can verify it the same way.
How it works
- The site (relying party) builds a SIWE message, usually with a server-generated
nonce. - The wallet shows it and signs it with the ERC-191
personal_signformat (\x19Ethereum Signed Message:\n<len>). - The server checks the message fields and the signature, then creates a session bound to the address.
The message is human-readable text with a strict grammar (defined in ABNF):
example.com wants you to sign in with your Ethereum account:
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
I accept the ExampleOrg Terms of Service: https://example.com/tos
URI: https://example.com/login
Version: 1
Chain ID: 1
Nonce: 32891756
Issued At: 2021-09-30T16:25:24Z
Required fields: domain, address (EIP-55 checksummed where applicable), URI, Version (1), Chain ID, Nonce (at least 8 alphanumerics) and Issued At. Optional: scheme, statement, Expiration Time, Not Before, Request ID and a list of Resources URIs.
Key rules:
- Wallets MUST check that
scheme/domainmatch the real origin of the request and must show at least the domain, address, statement and resources before signing. This is the anti-phishing core of the spec. - EOAs are verified with ERC-191
ecrecover; contract wallets SHOULD be verified with ERC-1271isValidSignatureon the chain given byChain ID. - Servers must verify the nonce, timing fields and domain, and bind the session to the address, not to things that can change such as an ENS name.
Sample code
Client side with ethers v6, building the message by hand:
import { BrowserProvider } from "ethers";
const provider = new BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
const address = await signer.getAddress();
const { chainId } = await provider.getNetwork();
const nonce = await fetch("/api/nonce").then((r) => r.text()); // server-generated
const message = [
`${window.location.host} wants you to sign in with your Ethereum account:`,
address,
"",
"Sign in to Example.",
"",
`URI: ${window.location.origin}`,
"Version: 1",
`Chain ID: ${chainId}`,
`Nonce: ${nonce}`,
`Issued At: ${new Date().toISOString()}`,
].join("\n");
const signature = await signer.signMessage(message); // ERC-191 personal_sign
await fetch("/api/verify", { method: "POST", body: JSON.stringify({ message, signature }) });
On the server, parse the message, check domain/nonce/expiry, then compare ethers.verifyMessage(message, signature) with the address (or call ERC-1271 for contract wallets).
Things to know
- Status: Final. Libraries exist (e.g. the
siwenpm package) that implement parsing and verification; prefer them over hand-rolled parsers. - Authentication only: authorisation and interpretation of
Resourcesare out of scope. ERC-5573 (ReCaps) builds capability delegation on top. - Use a fresh, high-entropy nonce per sign-in and reject reused ones, or a captured signature can be replayed.
- ERC-1271 results depend on chain state, so sessions for contract wallets may need invalidating when signers change.
- ERC-191 was chosen over EIP-712 because wallets display plain text more readably; the message is not designed for on-chain verification.