Skip to main content
type AccountActions = {
  requestFaucet: (options: Omit<RequestFaucetOptions, "address">) => Promise<SignatureResult>;
  sendTransaction: (options: Omit<SendTransactionOptions, "address">) => Promise<SendTransactionResult>;
  signMessage: (options: Omit<SignMessageOptions, "address">) => Promise<SignatureResult>;
  signTransaction: (options: Omit<SignTransactionOptions, "address">) => Promise<SignTransactionResult>;
  transfer: (options: Omit<TransferOptions, "from">) => Promise<SignatureResult>;
};
Defined in: actions/solana/types.ts:17

Properties

requestFaucet()

requestFaucet: (options: Omit<RequestFaucetOptions, "address">) => Promise<SignatureResult>;
Defined in: actions/solana/types.ts:38 Requests funds from a Solana faucet.

Parameters

options
Omit<RequestFaucetOptions, "address"> Parameters for requesting funds from the Solana faucet.

Returns

Promise<SignatureResult> A promise that resolves to the transaction hash.

Example

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

// Request funds from the Solana faucet
const result = await account.requestFaucet({
  token: "sol",
});

sendTransaction()

sendTransaction: (options: Omit<SendTransactionOptions, "address">) => Promise<SendTransactionResult>;
Defined in: actions/solana/types.ts:183 Sends a transaction.

Parameters

options
Omit<SendTransactionOptions, "address"> Parameters for sending the transaction.

Returns

Promise<SendTransactionResult> A promise that resolves to the transaction signature.

Example

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

// Build your transaction using @solana/kit
import {
  address as solanaAddress,
  appendTransactionMessageInstructions,
  compileTransaction,
  createNoopSigner,
  createSolanaRpc,
  createTransactionMessage,
  getBase64EncodedWireTransaction,
  pipe,
  setTransactionMessageFeePayer,
  setTransactionMessageLifetimeUsingBlockhash,
} from "@solana/kit";
import { getTransferSolInstruction } from "@solana-program/system";

const rpc = createSolanaRpc("https://api.devnet.solana.com");
const { value: { blockhash, lastValidBlockHeight } } = await rpc.getLatestBlockhash().send();

const txMsg = pipe(
  createTransactionMessage({ version: 0 }),
  (tx) => setTransactionMessageFeePayer(solanaAddress(account.address), tx),
  (tx) => setTransactionMessageLifetimeUsingBlockhash(
    { blockhash, lastValidBlockHeight },
    tx,
  ),
  (tx) => appendTransactionMessageInstructions([
    getTransferSolInstruction({
      source: createNoopSigner(solanaAddress(account.address)),
      destination: solanaAddress("3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE"),
      amount: 10000n,
    }),
  ], tx),
);

// Base64 encode the compiled transaction
const transaction = getBase64EncodedWireTransaction(compileTransaction(txMsg));

// Send the transaction via the CDP API
const { transactionSignature } = await account.sendTransaction({
  transaction,
});

signMessage()

signMessage: (options: Omit<SignMessageOptions, "address">) => Promise<SignatureResult>;
Defined in: actions/solana/types.ts:61 Signs a message.

Parameters

options
Omit<SignMessageOptions, "address"> Parameters for signing the message.

Returns

Promise<SignatureResult> A promise that resolves to the signature.

Example

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

// Sign a message
const { signature } = await account.signMessage({
  message: "Hello, world!",
});

signTransaction()

signTransaction: (options: Omit<SignTransactionOptions, "address">) => Promise<SignTransactionResult>;
Defined in: actions/solana/types.ts:121 Signs a transaction.

Parameters

options
Omit<SignTransactionOptions, "address"> Parameters for signing the transaction.

Returns

Promise<SignTransactionResult> A promise that resolves to the signature.

Example

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

// Build your transaction using @solana/kit
import {
  address as solanaAddress,
  appendTransactionMessageInstructions,
  compileTransaction,
  createNoopSigner,
  createSolanaRpc,
  createTransactionMessage,
  getBase64EncodedWireTransaction,
  pipe,
  setTransactionMessageFeePayer,
  setTransactionMessageLifetimeUsingBlockhash,
} from "@solana/kit";
import { getTransferSolInstruction } from "@solana-program/system";

const rpc = createSolanaRpc("https://api.devnet.solana.com");
const { value: { blockhash, lastValidBlockHeight } } = await rpc.getLatestBlockhash().send();

const txMsg = pipe(
  createTransactionMessage({ version: 0 }),
  (tx) => setTransactionMessageFeePayer(solanaAddress(account.address), tx),
  (tx) => setTransactionMessageLifetimeUsingBlockhash(
    { blockhash, lastValidBlockHeight },
    tx,
  ),
  (tx) => appendTransactionMessageInstructions([
    getTransferSolInstruction({
      source: createNoopSigner(solanaAddress(account.address)),
      destination: solanaAddress("3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE"),
      amount: 10000n,
    }),
  ], tx),
);

// Base64 encode the compiled transaction
const transaction = getBase64EncodedWireTransaction(compileTransaction(txMsg));

// Sign the transaction via the CDP API
const { signedTransaction } = await account.signTransaction({
  transaction,
});

transfer()

transfer: (options: Omit<TransferOptions, "from">) => Promise<SignatureResult>;
Defined in: actions/solana/types.ts:210 Transfers SOL or SPL tokens between accounts

Parameters

options
Omit<TransferOptions, "from"> Parameters for the transfer.

Returns

Promise<SignatureResult> A promise that resolves to the transaction signature, which can be used to wait for the transaction result.

Example

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

const { signature } = await account.transfer({
  token: "sol",
  amount: 5_000_000_000n, // 5 SOL in lamports
  to: "3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE",
  network: "devnet",
});