Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Authenticate a user with Sign-In with Ethereum using the unified MiniKit API.
MiniKit.walletAuth()
import { MiniKit } from "@worldcoin/minikit-js"; import type { CommandResultByVia, MiniKitWalletAuthOptions, WalletAuthResult, } from "@worldcoin/minikit-js/commands"; export async function signInWithWallet() { const response = await fetch("/api/nonce"); const { nonce } = await response.json(); const input = { nonce, statement: "Sign in to Example Mini App", expirationTime: new Date(Date.now() + 1000 * 60 * 60), // requestId: "optional-tracking-id", // notBefore: new Date(), } satisfies MiniKitWalletAuthOptions; const result: CommandResultByVia<WalletAuthResult> = await MiniKit.walletAuth(input); if (result.executedWith === "fallback") { return; } await fetch("/api/complete-siwe", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ payload: result.data, nonce, }), }); }
type MiniKitWalletAuthOptions = { nonce: string; statement?: string; expirationTime?: Date; notBefore?: Date; requestId?: string; fallback?: () => unknown; };
type WalletAuthResponse = | { executedWith: "minikit" | "wagmi"; data: { address: string; message: string; signature: string; }; } | { executedWith: "fallback"; data: unknown; };
{ "executedWith": "minikit", "data": { "address": "0x1234567890123456789012345678901234567890", "message": "example.com wants you to sign in with your Ethereum account", "signature": "0xabcdef1234567890" } }
import { cookies } from "next/headers"; import { NextRequest, NextResponse } from "next/server"; import type { MiniAppWalletAuthSuccessPayload } from "@worldcoin/minikit-js/commands"; import { verifySiweMessage } from "@worldcoin/minikit-js/siwe"; type RequestBody = { payload: MiniAppWalletAuthSuccessPayload; nonce: string; }; export async function POST(req: NextRequest) { const { payload, nonce } = (await req.json()) as RequestBody; if (nonce !== cookies().get("siwe")?.value) { return NextResponse.json( { isValid: false, error: "Invalid nonce" }, { status: 400 }, ); } try { // Optional: pass statement and requestId for additional server-side validation const verification = await verifySiweMessage( payload, nonce, // statement, — validates the statement matches what you sent // requestId, — validates the request ID matches what you sent // viemClient, — custom viem Client; defaults to a public Worldchain client ); return NextResponse.json({ isValid: verification.isValid, address: verification.siweMessageData.address, }); } catch (error) { return NextResponse.json( { isValid: false, error: error instanceof Error ? error.message : "Unknown error", }, { status: 400 }, ); } }
nonce
string
statement
expirationTime
Date
notBefore
requestId
fallback
() => Promise<T>
MiniKit.user.walletAddress
MiniKit.getUserByAddress()
MiniKit.getUserByUsername()
malformed_request
user_rejected
generic_error
Was this page helpful?