Skip to main content
Solana accounts in the CDP SDK are server-managed accounts that provide secure key management for the Solana blockchain. These accounts support all standard Solana operations including transfers, transaction signing, and message signing.

Creating a Solana Account

1

Initialize the CDP Client

Set up your CDP client:
import { CdpClient } from "@coinbase/cdp-sdk";

const cdp = new CdpClient();
2

Create a Solana account

Create a new Solana account with an optional name:
const account = await cdp.solana.createAccount({
  name: "MySolanaAccount"
});
console.log(`Created Solana account: ${account.address}`);
3

Create with a policy

Apply a Solana-specific policy during creation:
const account = await cdp.solana.createAccount({
  name: "RestrictedSolanaAccount",
  accountPolicy: "pol_sol_123..."
});

Retrieving Accounts

Get or Create Pattern

const account = await cdp.solana.getOrCreateAccount({ 
  name: "MySolanaAccount" 
});

Get by Address or Name

// By address
const account = await cdp.solana.getAccount({ 
  address: "9aE4..."
});

// By name
const account = await cdp.solana.getAccount({ 
  name: "MySolanaAccount" 
});

List All Accounts

const response = await cdp.solana.listAccounts({
  pageSize: 50,
  pageToken: "optional-token"
});

for (const account of response.accounts) {
  console.log(`${account.name}: ${account.address}`);
}

Updating Accounts

Update account name or policies:
const updatedAccount = await cdp.solana.updateAccount({
  address: account.address,
  name: "NewSolanaName",
  accountPolicy: "pol_sol_xyz..." // Optional
});

Transferring SOL and SPL Tokens

Transfer SOL or SPL tokens to another address:
// Transfer SOL
const signature = await account.transfer({
  to: "9aE4...",
  amount: 1000000n, // 0.001 SOL (in lamports)
  token: "sol",
  network: "solana-devnet"
});

// Transfer USDC (SPL token)
const signature = await account.transfer({
  to: "9aE4...",
  amount: 1000000n, // 1 USDC (6 decimals)
  token: "usdc",
  network: "solana-devnet"
});

console.log(`Transaction signature: ${signature}`);
SOL uses 9 decimal places (1 SOL = 1,000,000,000 lamports). Most SPL tokens use 6 or 9 decimals. Check the token’s decimals before transferring.

Signing Transactions

Sign a Solana transaction (base64-encoded):
const response = await account.signTransaction({
  transaction: "base64-encoded-transaction",
  idempotencyKey: "unique-key-123"
});

console.log(`Signed transaction: ${response.signedTransaction}`);

Signing Messages

Sign arbitrary messages (off-chain signatures):
const response = await account.signMessage({
  message: "Hello, Solana!",
  idempotencyKey: "unique-key-456"
});

console.log(`Message signature: ${response.signature}`);

Requesting Test Tokens

For devnet testing, request SOL or USDC from the faucet:
// Request SOL
const response = await account.requestFaucet("sol");
console.log(`Faucet transaction: ${response.transactionHash}`);

// Request USDC
const response = await account.requestFaucet("usdc");
Faucets are only available on devnet and testnet networks.

Account Properties

address
string
The Solana public key address (Base58-encoded)
name
string | null
Optional name for the account
policies
string[]
List of policy IDs applied to this account

Importing and Exporting

Import Account

const account = await cdp.solana.importAccount({
  privateKey: "base58-encoded-private-key",
  name: "ImportedSolanaAccount"
});

Export Account

const privateKey = await cdp.solana.exportAccount({ 
  address: account.address 
});
console.log(`Private key: ${privateKey}`);

Troubleshooting

Insufficient Lamports

Ensure your account has enough SOL to cover transaction fees (rent + gas):
// Request SOL from faucet on devnet
await account.requestFaucet("sol");

Transaction Failed

Solana transactions can fail due to:
  • Insufficient funds for rent or fees
  • Invalid program instructions
  • Network congestion
  • Blockhash expiration
Always check the transaction signature on a Solana explorer for detailed error messages.

Policy Restrictions

If a transaction is blocked, check the account’s applied policies. Solana policies can restrict:
  • Destination addresses
  • Program interactions
  • Token transfers
  • Maximum transaction amounts

Next Steps

Build docs developers (and LLMs) love