viem-siwe

Comprehensive guide and reference implementation for Sign-In with Ethereum (SIWE) using the viem v2 library. Use this skill when implementing authentication flows, verifying Ethereum addresses on a backend, parsing EIP-4361 messages, or managing SIWE sessions. It includes nonce generation, message creation, signature verification, and best practices for replay protection and session management.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "viem-siwe" with this command: npx skills add melonask/viem-siwe-skills/melonask-viem-siwe-skills-viem-siwe

Viem SIWE

This skill provides expertise in implementing Sign-In with Ethereum (SIWE) adhering to EIP-4361 using viem.

Reference Implementation

For a complete, copy-pasteable implementation of a SIWE auth module, refer to references/implementation.md.

This implementation includes:

  • siwe.ts: Core logic for nonce generation, message creation, parsing, and verification.
  • index.ts: Public API for the auth module.

API Documentation

For detailed API documentation of viem's SIWE utilities (createSiweMessage, verifySiweMessage, etc.), refer to references/api-docs.md.

Critical Implementation Details

Nonce Management

  • Always generate a unique nonce for every login attempt.
  • Store nonces with an expiration (TTL) on the backend.
  • Verify and consume the nonce upon signature validation to prevent replay attacks.

Message Verification

  • Verify Domain: Ensure the domain in the message matches the host to prevent phishing.
  • Verify Chain ID: Ensure the chainId matches the expected network.
  • Check Expiration: Respect expirationTime and notBefore fields.

Smart Contract Wallets (ERC-1271)

When verifying signatures from smart contract wallets:

  • Use a PublicClient instance in verifySiweMessage.
  • Do not rely solely on verifyMessage which only works for EOAs.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

viem-sweep

No summary provided by upstream source.

Repository SourceNeeds Review
General

universal-signer

No summary provided by upstream source.

Repository SourceNeeds Review
General

evm-address

No summary provided by upstream source.

Repository SourceNeeds Review
General

eip-7702

No summary provided by upstream source.

Repository SourceNeeds Review