Skip to main content
This guide will help you create your first smart account using the Squads API. For a complete overview of the API capabilities, see the API Introduction.

Prerequisites

Before you begin, make sure you have:

Making API Requests

All requests should be made to the base URL: https://developer-api.squads.so Include your API key and network in the request headers of every request:
Authorization: Bearer YOUR_API_KEY
x-squad-network: devnet // or 'mainnet' for production

Create your first smart account

Create a basic smart account with a single signer. For more details about smart account creation and management, see the Create Smart Account documentation.
const response = await fetch(
  "https://developer-api.squads.so/api/v0/smart_account/transaction/create",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      "x-squad-network": "devnet",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      smart_account_signers: [
        {
          address: "YOUR_WALLET_ADDRESS",
          permissions: ["CAN_INITIATE", "CAN_VOTE", "CAN_EXECUTE"],
        },
      ],
      threshold: 1,
    }),
  }
);

const { smart_account_address } = await response.json();
console.log(`Smart Account created: ${smart_account_address}`);
That’s it! Your smart account is ready to use immediately. No transaction submission or fee payment required. You can later add more signers or set up spending limits as needed.

Create a token transfer

Let’s create a token transfer transaction using your new smart account. We’ll break this down into steps:

1. Set up the transfer instruction

First, import the required dependencies and create the token transfer instruction:
import { createTransferInstruction } from "@solana/spl-token";
import {
  Connection,
  PublicKey,
  TransactionMessage,
  VersionedTransaction
} from "@solana/web3.js";

// Initialize connection to Solana
const connection = new Connection("https://api.devnet.solana.com");

// Create the token transfer instruction
const transferInstruction = createTransferInstruction(
  new PublicKey("SOURCE_TOKEN_ACCOUNT"),    // The smart account's token account
  new PublicKey("DESTINATION_TOKEN_ACCOUNT"),
  new PublicKey(smart_account_address),     // The smart account is the authority
  1000000n                                  // Amount (e.g., 1 USDC)
);

2. Create a versioned transaction

Next, create a V0 transaction message with the latest blockhash:
// Get the latest blockhash
const latestBlockhash = await connection.getLatestBlockhash();

// Create a V0 transaction message
const message = new TransactionMessage({
  payerKey: new PublicKey(smart_account_address),
  recentBlockhash: latestBlockhash.blockhash,
  instructions: [transferInstruction]
}).compileToV0Message();

// Create and serialize the transaction
const transaction = new VersionedTransaction(message);
const serializedTransaction = Buffer.from(
  transaction.serialize()
).toString('base64');

3. Prepare the transaction

Send the transaction to the Squads API for preparation. This step will:
  • Add the necessary program instructions
  • Configure fee payment
  • Return the prepared transaction and fee details
const prepareResponse = await fetch(
  "https://developer-api.squads.so/api/v0/smart_account/transaction/prepare",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      "x-squad-network": "devnet",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      smart_account_address,
      transaction: serializedTransaction,
      transaction_signers: ["YOUR_WALLET_ADDRESS"],
      fee_config: {
        currency: "usdc",        // Choose 'usdc' or 'sol'
        payer_address: "YOUR_FEE_PAYER_ADDRESS",
      },
    }),
  }
);

// Get the prepared transaction and fee information
const { transaction: preparedTransaction, fee } = await prepareResponse.json();

// Log the fee details
console.log(
  `Transaction prepared! Fee: ${fee.amount_decimal} ${fee.currency.toUpperCase()}`
);
console.log(
  `Fee in SOL: ${fee.sol_equivalent.amount_decimal} SOL`
);

4. Sign and submit the transaction

Finally, sign the prepared transaction with your wallet and submit it to Solana:
// Decode the prepared transaction
const decodedTransaction = VersionedTransaction.deserialize(
  Buffer.from(preparedTransaction, "base64")
);

// Sign with your wallet
decodedTransaction.sign([wallet]);

// Submit to Solana
const signature = await connection.sendRawTransaction(
  decodedTransaction.serialize()
);
console.log(`Transaction sent: ${signature}`);

// Wait for confirmation
const confirmation = await connection.confirmTransaction({
  signature,
  blockhash: latestBlockhash.blockhash,
  lastValidBlockHeight: latestBlockhash.lastValidBlockHeight
});
console.log("Transfer complete!");
Each step builds on the previous one to create a complete token transfer flow. The Squads API handles the complexity of smart account execution, allowing you to focus on building your application logic.

Next steps

Add Spending Limits

Learn how to add spending controls

Explore the API

View detailed API documentation