Overview
Relay is a cross-chain protocol for bridging tokens and swapping assets across networks. This guide demonstrates integrating Turnkey wallets with Relay to enable cross-chain bridging and same-chain token swaps, covering authentication, quote fetching, multi-step execution, and intent status polling. Therelay turnkey example is a Next.js application that bridges ETH from Base to Arbitrum and swaps ETH for USDC on Base.
Prerequisites
Complete the Turnkey Quickstart first. You’ll need:- A Turnkey organization and Auth Proxy Config ID
- (Optional) A Relay API key for higher rate limits
Installation
Wallet configuration
The@turnkey/react-wallet-kit package handles browser-based authentication. Each new user gets a Turnkey sub-organization with an HD wallet provisioned automatically on first login. Use @turnkey/viem’s createAccount to turn the active session into a viem Account:
Relay integration
Call the Relay API from Next.js server actions to keep the API key server-side. The/quote/v2 endpoint returns an executable quote with all transaction calldata and signature payloads:
Executing a quote
A Relay quote contains an array of steps, each of kind"transaction" or "signature". Iterate through all steps and dispatch them in order using the Turnkey-backed wallet client:
Polling for completion
After submitting a step (e.g. the deposit transaction), Relay’s solver detects the deposit and fills the request on the destination chain. To know when the full flow is done, poll the intent status endpoint. Each step item in the quote can include acheck object with an endpoint to call:
https://api.relay.link/intents/status/v3?requestId=<requestId>) periodically (e.g. once per second) until the status indicates completion. The requestId is available on each step in the quote response.
Status lifecycle: Typical values include waiting (user submitted deposit, not yet indexed), depositing (deposit confirmed, preparing fill), pending (deposit indexed, solver preparing fill on destination), and success (fill executed, funds reached the recipient). For the full list and behavior, see Relay’s status lifecycle documentation.
For a real-time stream instead of polling, you can use Relay’s WebSocket API.
Handling EIP-191 and EIP-712 signatures
Some Relay steps (particularly for swaps) require off-chain signatures before the deposit transaction. Handle both signature kinds with the Turnkey-backed viem wallet client:Key takeaways
✅ Successfully implemented:- Turnkey authentication using
@turnkey/react-wallet-kitwith passkey and email OTP support - Relay cross-chain bridging and same-chain swaps via the
/quote/v2API - Multi-step quote execution handling both
transactionandsignaturestep kinds - Intent status polling to confirm completion using the quote’s
checkendpoint andrequestId - EIP-191 and EIP-712 signing through the Turnkey-backed viem account
- Server-side API key protection using Next.js server actions