Skip to content

Authentication

All trading endpoints on the Synthetix API require authentication using EIP-712 signatures. This section provides comprehensive guidance on implementing secure authentication for both REST and WebSocket APIs.

Quick Start

  1. Overview - Understanding the authentication system
  2. EIP-712 Signing - Cryptographic signature implementation
  3. Nonce Management - Preventing replay attacks
  4. Examples - Ready-to-use code samples
  5. Troubleshooting - Debug common authentication issues

Authentication Flow

1. Generate Nonce

2. Create Message

3. Sign with EIP-712

4. Send Request

5. API Validates Signature

6. Execute Operation

Key Concepts

EIP-712 Signatures

  • Type Safety: Structured data signing prevents errors
  • Human Readable: Clear display of what you're signing
  • Hardware Wallet Support: Compatible with Ledger, Trezor, etc.
  • Phishing Protection: Domain separation prevents attack vectors

Nonce Management

  • Replay Protection: Each request uses a unique, incrementing nonce
  • Timestamp Based: Nonces are typically Unix timestamps in milliseconds
  • Order Enforcement: Nonces must be strictly increasing per account

Subaccount Support

  • Multiple Accounts: Trade across multiple subaccounts under one wallet
  • Secure Access: Signature determines authorization for subaccount operations

Authentication Requirements

Endpoint TypeAuthentication Required
Info EndpointsNo - Public market data
Trade EndpointsYes - EIP-712 signature required
WebSocket InfoNo - Public subscriptions
WebSocket TradeYes - Initial auth + per-action signatures

Authentication Flow Details

REST API

Each request to the Trade endpoint requires its own EIP-712 signature containing:

  • Request data (orders, cancellations, modifications)
  • Subaccount ID
  • Nonce (timestamp for replay protection)
  • Optional expiration time

WebSocket API

Two-step authentication process:

  1. Initial Authentication: Sign WebSocket auth message with subAccountId, timestamp, and action: "websocket_auth"
  2. Per-Action Signatures: Each trading action still requires individual EIP-712 signatures

Error Handling

Common authentication errors and solutions:

ErrorCauseSolution
Invalid signatureWrong signing parametersVerify domain, types, and message structure
Nonce already usedReplay attack protectionUse a fresh, incrementing nonce
Request expiredClock drift or slow requestIncrease expiration buffer
Unauthorized subaccount accessMissing delegation permissionsVerify delegation for subaccount

Next Steps

Related Resources