Start building with Grid Accounts in minutes with step-by-step integration instructions
Grid Accounts make it simple to build modern fintech applications with email-based onboarding, programmable spending limits, and sub-penny transaction costs. This guide will get you up and running in minutes.
Grid Accounts currently support any Solana token and are compatible with
Solana-based programs, providing a powerful base for composability.
Migrating from grid-sdk? The new @sqds/grid package provides enhanced
features including multi-provider support and React Native compatibility. View
our migration guide.
import { GridClient } from "@sqds/grid";// Initialize the Grid clientconst gridClient = new GridClient({ environment: "sandbox", // Use 'production' for live applications apiKey: process.env.GRID_API_KEY!, // Your API key from the dashboard baseUrl: "https://grid.squads.xyz", // Base URL of the Grid API});// Verify the connectionconsole.log("Grid client initialized successfully");
The Grid SDK automatically handles API authentication, request retries, and
error formatting. You don’t need to build your own HTTP client.
Complete workflow from account creation through transaction execution:
1
Initialize Grid Client
Set up your Grid SDK client with API credentials:
Copy
Ask AI
import { GridClient } from '@sqds/grid';const gridClient = new GridClient({ environment: 'sandbox', // Use 'production' for live applications apiKey: process.env.GRID_API_KEY!, baseUrl: "https://grid.squads.xyz",});
2
Generate Session Secrets
Create cryptographic keypairs that will authorize all future transactions:
Copy
Ask AI
const sessionSecrets = await gridClient.generateSessionSecrets();console.log('Session secrets generated - these contain private keys needed for signing!');
Session secrets contain private keys that enable transaction signing. Store them encrypted and never expose them in client-side code.
3
Create Email Account
Create a new Grid account using email-based onboarding:
Grid accounts do not have the same address in sandbox and production. DO NOT send funds to the same address in both environments. Create unique accounts for each environment and ensure you use the correct address for your environment.
Copy
Ask AI
const user = await gridClient.createAccount({ email: 'user@example.com',});console.log('Account creation initiated for:', user.email);console.log('OTP sent to email for verification');
4
Verify Account with OTP
Complete account verification using the OTP sent to the user’s email:
Copy
Ask AI
const verifiedAccount = await gridClient.completeAuthAndCreateAccount({ user: user, otpCode: '123456', // User receives this via email sessionSecrets: sessionSecrets,});console.log('Account created successfully');
5
Authenticate Existing Account (Alternative)
For users who already have a Grid account, use the authentication flow:
Copy
Ask AI
// Generate fresh session secrets for authenticationconst authSessionSecrets = await gridClient.generateSessionSecrets();// Initialize authentication for existing accountconst authUser = await gridClient.initAuth({ email: 'existing@example.com',});console.log('Authentication initiated for:', authUser.email);console.log('OTP sent to email for verification');// Complete authentication with OTPconst authenticatedAccount = await gridClient.completeAuth({ user: authUser, otpCode: '123456', // User receives this via email sessionSecrets: authSessionSecrets,});console.log('Account authenticated successfully');
Use initAuth and completeAuth for existing accounts, or createAccount and completeAuthAndCreateAccount for new account creation. Always generate fresh session secrets for each authentication flow.
6
Prepare Transaction
Before executing, prepare the transaction payload using the SDK:
Copy
Ask AI
const rawTransactionPayload = { transaction: "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArc20SI/X2z8FPQhKgWWbWfXOTI3TDjuQQB8JfpF+1e4u3shfDGrJc7jvYd11DguvNKYg2PsUz7b7GZKwcAjMBoCAAECAAkDAAAAAMOhGsIAAAAA", // Your Solana transaction transaction_signers: [verifiedAccount.address] // Optional: only needed when signing with local signers};// Prepare the transaction payloadconst transactionPayload = await gridClient.prepareArbitraryTransaction( verifiedAccount.address, rawTransactionPayload);console.log('Transaction prepared successfully');
The transaction_signers field is optional and only required when you need to sign the transaction with additional local signers alongside Grid’s signing.
7
Execute Transactions
Use the signAndSend method to execute the prepared transaction:
The signAndSend method handles both cryptographic signing and network submission in a single call, simplifying transaction execution.
For production applications, implement proper error handling, retry logic, and secure secret management around each of these steps.
Ready to go live? Make sure to update your API endpoints to production URLs
and use your production API keys. Grid provides the same API structure across
sandbox and production environments.