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: '[email protected]',});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: '[email protected]',});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.
Comprehensive LLM prompts that provide complete implementation guidance for Grid Accounts integration:
1
Step 1: Initialize Grid Client Setup
Copy this comprehensive prompt to your LLM:
Copy
Ask AI
# IMPLEMENT GRID ACCOUNTS CLIENT SETUP## TASK OVERVIEWSet up Grid SDK client initialization in my application following my existing patterns.## MY APPLICATION CONTEXT**Tech Stack:**- Framework: [React/Next.js/Express/Django/etc.]- Environment management: [How you handle config/env vars]- Service architecture: [How you organize API services]- Error handling: [Your current error handling approach]## GRID V1 CLIENT REQUIREMENTS**Installation:** npm install @sqds/grid**Import:** import { GridClient } from '@sqds/grid';**Configuration Options:**- environment: 'sandbox' | 'production'- apiKey: string (from Grid dashboard at https://grid.squads.xyz/dashboard)**Complete Initialization Example:**const gridClient = new GridClient({ environment: process.env.NODE_ENV === 'production' ? 'production' : 'sandbox', apiKey: process.env.GRID_API_KEY!, baseUrl: "https://grid.squads.xyz",});## IMPLEMENTATION REQUESTCreate a Grid client service that:1. Follows my application's service patterns2. Handles environment configuration properly3. Includes comprehensive error handling4. Provides a clean interface for other parts of my app5. Includes proper TypeScript types if I'm using TypeScriptShow me the complete implementation with file structure and code.## DOCUMENTATION REFERENCES- Grid SDK Documentation: https://www.npmjs.com/package/@sqds/grid- API Dashboard: https://grid.squads.xyz/dashboard
2
Step 2: Generate and Store Session Secrets
Copy this comprehensive prompt to your LLM:
Copy
Ask AI
# IMPLEMENT GRID SESSION SECRETS MANAGEMENT## TASK OVERVIEWImplement secure generation and storage of Grid session secrets for transaction signing.## MY APPLICATION CONTEXT**Security Setup:**- Current encryption library: [crypto/bcrypt/etc.]- Database/storage: [PostgreSQL/MongoDB/Redis/etc.]- User data storage patterns: [How you store user information]- Environment variables: [Your env var management]## GRID SESSION SECRETS EXPLAINEDSession secrets are cryptographic keypairs that authorize transaction signing. They contain:- Private keys for signing transactions- Public keys for verification- CRITICAL: Must never be exposed in client-side code or logs**Generation Method:**const sessionSecrets = await gridClient.generateSessionSecrets();// Returns object with signing keys - treat as highly sensitive## SECURITY REQUIREMENTS1. **Encrypt before storage** - Never store plaintext2. **Server-side only** - Never send to client3. **Secure key management** - Use environment variables for encryption keys4. **Access logging** - Log when secrets are accessed## IMPLEMENTATION REQUESTCreate a secure session secrets management system that:1. Generates session secrets using Grid SDK2. Encrypts them using my existing encryption approach3. Stores encrypted secrets in my database4. Provides secure retrieval and decryption5. Includes proper error handling for encryption/decryption failures6. Follows my application's security patternsShow me the complete implementation including database schema, encryption/decryption functions, and service methods.## DOCUMENTATION REFERENCES- Grid SDK Documentation: https://www.npmjs.com/package/@sqds/grid- Authentication Methods Guide: https://grid.squads.xyz/grid/v1/accounts/authentication-methods
3
Step 3: Implement Account Creation Flow
Copy this comprehensive prompt to your LLM:
Copy
Ask AI
# IMPLEMENT GRID ACCOUNT CREATION WITH EMAIL AUTHENTICATION## TASK OVERVIEWIntegrate Grid account creation into my user registration flow with email-based authentication.## MY APPLICATION CONTEXT**Current User Registration:**- Registration flow: [Describe your signup process]- User data model: [Your user schema/model]- Email handling: [How you send emails/notifications]- Database operations: [Your ORM/database pattern]## GRID ACCOUNT CREATION PROCESS**Step 1:** Generate session secrets (from previous step)**Step 2:** Create account with email**Step 3:** Handle OTP verification**Account Creation Method:**const accountData = await gridClient.createAccount({ email: '[email protected]',});// Returns: { address: string, ... }// Automatically sends OTP to email**Account Verification Method:**const verifiedAccount = await gridClient.completeAuthAndCreateAccount({ user: user, otpCode: '123456', // From user email sessionSecrets: sessionSecrets,});// Returns verified account session**For Existing Accounts (Alternative):**// Generate fresh session secrets for authenticationconst authSessionSecrets = await gridClient.generateSessionSecrets();// Initialize authentication for existing accountconst authUser = await gridClient.initAuth({ email: '[email protected]',});// Complete authentication with OTPconst authenticatedAccount = await gridClient.completeAuth({ user: authUser, otpCode: '123456', // From user email sessionSecrets: authSessionSecrets,});// Returns authenticated account session## INTEGRATION REQUIREMENTS1. **Integrate with existing registration** - Add Grid account creation to my signup flow2. **Handle existing users** - Support both new account creation and existing account authentication3. **Store account data** - Save Grid address and session info4. **Handle OTP flow** - Create UI/API for OTP verification5. **Link to user records** - Associate Grid accounts with my user model6. **Error handling** - Handle network failures, invalid emails, expired OTPs## IMPLEMENTATION REQUESTShow me how to:1. Modify my user registration to include Grid account creation2. Add existing user authentication flow using initAuth/completeAuth3. Update my user model/schema to store Grid data4. Create OTP verification endpoints/UI5. Handle both new account creation and existing account authentication flows6. Add appropriate error handling and user feedbackProvide complete code examples that integrate with my existing patterns.## DOCUMENTATION REFERENCES- Grid SDK Documentation: https://www.npmjs.com/package/@sqds/grid- Authentication Methods Guide: https://grid.squads.xyz/grid/v1/accounts/authentication-methods
4
Step 4: Implement Transaction Preparation
Copy this comprehensive prompt to your LLM:
Copy
Ask AI
# IMPLEMENT GRID TRANSACTION PREPARATION## TASK OVERVIEWImplement transaction preparation for executing Solana transactions through Grid accounts.## MY APPLICATION CONTEXT**Current Transaction Flow:**- Payment/transaction handling: [How you process payments]- Transaction data: [How you structure transaction info]- Business logic: [Your transaction validation/processing]## GRID TRANSACTION PREPARATION EXPLAINEDBefore executing transactions, you must prepare the transaction payload:**Raw Transaction Structure:**const rawTransactionPayload = { transaction: "BASE64_ENCODED_SOLANA_TRANSACTION", // Your Solana transaction transaction_signers: [accountAddress] // Optional: additional local signers};**Preparation Method:**const transactionPayload = await gridClient.prepareArbitraryTransaction( accountAddress, rawTransactionPayload);**Key Points:**- `transaction`: Base64-encoded Solana transaction bytes- `transaction_signers`: Optional array for additional signing requirements- Returns prepared payload ready for signing and submission## SOLANA TRANSACTION CONTEXTGrid works with any Solana transaction including:- Token transfers (SPL tokens, stablecoins)- Program interactions (DeFi protocols, NFTs)- Smart contract calls- Multi-signature operations## IMPLEMENTATION REQUESTCreate a transaction preparation service that:1. Accepts transaction data from my application2. Converts it to proper Solana transaction format3. Uses Grid's prepareArbitraryTransaction method4. Handles different transaction types I need5. Includes validation and error handling6. Integrates with my existing transaction flowShow me:- How to structure different types of transactions for Grid- Complete transaction preparation implementation- Integration with my existing payment/transaction system- Error handling for invalid transactions## DOCUMENTATION REFERENCES- Grid SDK Documentation: https://www.npmjs.com/package/@sqds/grid- Automated Workflows Guide: https://grid.squads.xyz/grid/v1/accounts/automated-workflows
5
Step 5: Implement Transaction Execution
Copy this comprehensive prompt to your LLM:
Copy
Ask AI
# IMPLEMENT GRID TRANSACTION EXECUTION## TASK OVERVIEWImplement the final step: executing prepared transactions using Grid's signAndSend method.## MY APPLICATION CONTEXT**Transaction Processing:**- Current payment completion: [How you finalize transactions]- Transaction logging: [How you track transaction history]- User feedback: [How you notify users of transaction status]## GRID TRANSACTION EXECUTION**signAndSend Method Signature:**const executedTx = await gridClient.signAndSend({ sessionSecrets, // Decrypted session secrets from secure storage session: verifiedAccount, // Account session from authentication transactionPayload, // Prepared transaction from previous step address: accountAddress // Grid account address});// Returns: { signature: string, ... } - Solana transaction signature**Complete Flow:**1. Retrieve and decrypt user's session secrets2. Get user's verified account session3. Use prepared transaction payload4. Execute with signAndSend5. Handle success/failure and update user## IMPLEMENTATION REQUIREMENTS1. **Secure secret retrieval** - Get and decrypt session secrets safely2. **Transaction execution** - Use signAndSend method properly3. **Result handling** - Process success/failure responses4. **Transaction tracking** - Log results in my system5. **User feedback** - Notify users of transaction status6. **Error recovery** - Handle network failures, signing errors## COMMON TRANSACTION SCENARIOS- **Stablecoin transfers** - Moving USDC/USDT between accounts- **Payment processing** - Merchant payment acceptance- **DeFi interactions** - Yield farming, swaps, lending- **Batch operations** - Multiple transactions in sequence## IMPLEMENTATION REQUESTCreate a complete transaction execution system that:1. Integrates with my transaction preparation (previous step)2. Handles secure session secret management3. Executes transactions using Grid's signAndSend4. Provides comprehensive error handling and retry logic5. Updates my application state based on transaction results6. Includes proper logging and user notificationsShow me the complete implementation with all error scenarios handled.## DOCUMENTATION REFERENCES- Grid SDK Documentation: https://www.npmjs.com/package/@sqds/grid- Fault Tolerance Guide: https://grid.squads.xyz/grid/v1/accounts/fault-tolerance
Each prompt is self-contained with complete context, specifications, and documentation links. Copy any prompt to your LLM along with your specific technical details for comprehensive implementation guidance.
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.