Required: Node.js 16+ with npmCheck:node --version
Grid API Key
Get yours:Grid DashboardEnvironment: Use
sandbox for testing
1
Install and Setup
Install the SDK and configure your Grid client:
Copy
Ask AI
npm install @sqds/grid
Copy
Ask AI
// .env fileGRID_API_KEY=your-api-key-hereGRID_ENVIRONMENT=sandbox// Your applicationimport { GridClient } from '@sqds/grid';const gridClient = new GridClient({ environment: process.env.GRID_ENVIRONMENT as 'sandbox' | 'production', apiKey: process.env.GRID_API_KEY!, baseUrl: 'https://grid.squads.xyz'});
2
Create Account
Choose your account type and create your Grid account:
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
// 1. Initiate account creation with your emailconst response = await gridClient.createAccount({ email: "user@example.com", // Replace with your email});const user = response.data;// 2. Generate session secrets for secure authenticationconst sessionSecrets = await gridClient.generateSessionSecrets();// 3. Complete authentication with OTP from email (check inbox/spam)const authResult = await gridClient.completeAuthAndCreateAccount({ user, otpCode: "123456", // 6-digit code from email sessionSecrets,});if(authResult.success){ console.log("Account created successfully!"); console.log("Address:", authResult.data?.address); console.log("Session:", authResult.data?.authentication); LocalState.saveState("user", authResult.data);} else { console.log('❌ error authResult: ', authResult);}
Email-based accounts: Check your email for the 6-digit OTP code. It may take 1-2 minutes to arrive and could be in your spam folder.Custom signer accounts: Store your keypairs securely - you’ll need them to sign transactions.
Show Troubleshooting Account Creation
Common Issues:
OTP not received: Check spam folder, wait up to 2 minutes, or request a new code
Invalid OTP error: Ensure you’re using the latest 6-digit code from your email
Email already exists: Each email can only have one Grid account in sandbox
Network timeouts: Account creation typically takes 5-10 seconds
Response format:
Copy
Ask AI
{ success: true, data: { address: "GRIDxxxxx...", // Your account address grid_user_id: "xxxx....", authentication: [...] // Session data }}
3
Send Your First Transaction
Create a spending limit and execute your first transaction:
Copy
Ask AI
// Create spending limit transactionconst spendingLimitPayload = { amount: 100000, // 0.1 USDC (USDC uses 6 decimal places) mint: "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU", // USDC token mint period: "one_time", // Options: 'one_time' | 'daily' | 'weekly' | 'monthly'; destinations: ["DESTINATION_ADDRESS"], // Replace with actual destination};const result = await gridClient.createSpendingLimit( authResult.address, spendingLimitPayload);// Sign and submit with managed authenticationconst signature = await gridClient.signAndSend({ sessionSecrets, // From account creation step session: authResult.authentication, // Auth token from previous step transactionPayload: result.data, // Transaction data from spending limit creation address: authResult.address, // Your account address});console.log("Transaction executed successfully!");console.log("Signature:", signature);
What this does: Creates a spending policy allowing one-time transfers of
up to 0.1 USDC to specified addresses. This is a foundational building block
for payment flows.
Show Transaction Troubleshooting
Common Issues:
Destination address format: Must be a valid Solana address (base58 encoded)