Skip to main content

Overview

The SolanaAccount represents a server-managed Solana account that provides signing capabilities and blockchain interaction methods for the Solana network.

Type Definition

type SolanaAccount = {
  address: string;
  name?: string;
  policies?: string[];
  publicKey: string;
  signMessage: (options: { message: string }) => Promise<SignatureResult>;
  signTransaction: (options: { transaction: string }) => Promise<SignTransactionResult>;
};

Properties

address
string
required
The Solana address of the account (base58 encoded).
name
string
Optional name for the account.
policies
string[]
Array of Policy IDs that apply to the account.
publicKey
string
required
The public key of the account (base58 encoded).

Methods

signMessage

Signs a message and returns the signature.
options
object
required
signature
string
The signature as a base58 encoded string.
const result = await account.signMessage({
  message: "Hello, Solana!",
});

console.log("Signature:", result.signature);

signTransaction

Signs a Solana transaction and returns the signed transaction.
options
object
required
signedTransaction
string
The signed transaction as a base64 encoded string.
signature
string
The signature as a base58 encoded string.
import { Transaction, SystemProgram, PublicKey } from "@solana/web3.js";

// Create a Solana transaction
const transaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: new PublicKey(account.address),
    toPubkey: new PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),
    lamports: 1000000, // 0.001 SOL
  })
);

// Serialize with requireAllSignatures: false
const serializedTx = transaction.serialize({
  requireAllSignatures: false,
});

// Sign the transaction
const result = await account.signTransaction({
  transaction: Buffer.from(serializedTx).toString("base64"),
});

console.log("Signed transaction:", result.signedTransaction);

SolanaClient Methods

The following methods are available through cdp.solana:

createAccount

Creates a new Solana account.
options
object
account
SolanaAccount
The created Solana account.
const account = await cdp.solana.createAccount({
  name: "My Solana Account",
});

getAccount

Retrieves an existing Solana account.
options
object
required
account
SolanaAccount
The retrieved account.
// By address
const account = await cdp.solana.getAccount({
  address: "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
});

// By name
const account = await cdp.solana.getAccount({
  name: "My Solana Account",
});

getOrCreateAccount

Retrieves an account by name, or creates it if it doesn’t exist.
options
object
required
account
SolanaAccount
The account (existing or newly created).
const account = await cdp.solana.getOrCreateAccount({
  name: "My Solana Account",
});

listAccounts

Lists all Solana accounts.
options
object
accounts
SolanaAccount[]
Array of Solana accounts.
nextPageToken
string
Token for next page.
let page = await cdp.solana.listAccounts();

while (page.nextPageToken) {
  page = await cdp.solana.listAccounts({
    pageToken: page.nextPageToken,
  });
}

updateAccount

Updates a Solana account.
options
object
required
account
SolanaAccount
The updated account.
const account = await cdp.solana.updateAccount({
  address: "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
  update: {
    name: "Updated Name",
  },
});

importAccount

Imports a Solana account using a private key.
options
object
required
account
SolanaAccount
The imported account.
const account = await cdp.solana.importAccount({
  privateKey: "3Kzj...", // base58 encoded private key
  name: "Imported Account",
});

exportAccount

Exports a Solana account’s private key.
options
object
required
privateKey
string
The 64-byte private key as a base58 encoded string.
const privateKey = await cdp.solana.exportAccount({
  address: "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
});

// Store securely!
console.log("Private key:", privateKey);

listTokenBalances

Lists token balances for a Solana account.
options
object
required
balances
SolanaTokenBalance[]
Array of token balances.
const { balances } = await cdp.solana.listTokenBalances({
  address: account.address,
  network: "solana-devnet",
});

balances.forEach(balance => {
  console.log(`${balance.token.symbol}: ${balance.amount.amount}`);
});

requestFaucet

Requests testnet funds from a Solana faucet.
options
object
required
signature
string
The transaction signature.
const result = await cdp.solana.requestFaucet({
  address: account.address,
  token: "sol",
});

console.log("Faucet signature:", result.signature);

sendTransaction

Sends a Solana transaction to the network.
options
object
required
signature
string
The transaction signature.
const result = await cdp.solana.sendTransaction({
  network: "solana-devnet",
  transaction: signedTransaction,
});

console.log("Transaction signature:", result.signature);

signMessage

Signs a message with a Solana account.
options
object
required
signature
string
The signature.
const result = await cdp.solana.signMessage({
  address: account.address,
  message: "Hello, Solana!",
});

signTransaction

Signs a Solana transaction.
options
object
required
signature
string
The signature.
signedTransaction
string
The signed transaction.
const result = await cdp.solana.signTransaction({
  address: account.address,
  transaction: serializedTransaction,
});

Example: Complete Transfer Flow

import { CdpClient } from "@coinbase/cdp-sdk";
import { Transaction, SystemProgram, PublicKey, Connection } from "@solana/web3.js";

const cdp = new CdpClient();

// Create account
const account = await cdp.solana.createAccount();

// Request testnet funds
await cdp.solana.requestFaucet({
  address: account.address,
  token: "sol",
});

// Create and sign transaction
const connection = new Connection("https://api.devnet.solana.com");

const transaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: new PublicKey(account.address),
    toPubkey: new PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),
    lamports: 1000000,
  })
);

transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
transaction.feePayer = new PublicKey(account.address);

const serializedTx = transaction.serialize({
  requireAllSignatures: false,
});

const signedResult = await cdp.solana.signTransaction({
  address: account.address,
  transaction: Buffer.from(serializedTx).toString("base64"),
});

// Send transaction
const result = await cdp.solana.sendTransaction({
  network: "solana-devnet",
  transaction: signedResult.signedTransaction,
});

console.log("Transaction signature:", result.signature);

Build docs developers (and LLMs) love