Authentication

The DEX uses Sign-In with Ethereum (ERC-4361) for authentication. Authentication is required for private endpoints such as preparing orders and vault operations; public market data endpoints do not require it.

To authenticate, first request a nonce, include it in a SIWE message signed by your wallet, then submit the signed message to receive a JWT bearer token.

The Chain ID field in the SIWE message identifies the target network and must match the environment you are trading on: 5031 for Somnia mainnet, 50312 for Somnia Shannon testnet. It is the same chain ID carried in the chainId field of the unsigned transactions the API returns, so the login message and the orders you broadcast are signed against the same network.

Token lifetime and refresh

The JWT is valid for 1 hour. The login response includes an expiresAt field (Unix milliseconds) - the exact expiry; do not hard-code the duration. There is no refresh endpoint: to stay authenticated you re-run the full nonce → sign → login flow to obtain a fresh token. Once expired, requests to private endpoints return unauthorized (401).

24/7 agents. Track expiresAt and re-login proactively - a minute or two before expiry - rather than waiting for a 401. Each re-login needs a fresh nonce and a new signature, so the bot's signing key must remain available for the lifetime of the process. Since re-login is a wallet signature (not an on-chain transaction), it costs no gas.

GET /v0/auth/nonce

POST /v0/auth/login