The namespace containing all Solana methods.

Implements

Constructors

Methods

  • Creates a new Solana account.

    Parameters

    • options: CreateAccountOptions = {}

      Parameters for creating the Solana account.

      Options for creating a Solana account.

      • OptionalidempotencyKey?: string

        The idempotency key.

      • Optionalname?: string

        The name of the account.

    Returns Promise<SolanaAccount>

    A promise that resolves to the newly created account.

             const account = await cdp.solana.createAccount();
             const account = await cdp.solana.createAccount({ name: "MyAccount" });
             const idempotencyKey = uuidv4();

    // First call
    await cdp.solana.createAccount({ idempotencyKey });

    // Second call with the same idempotency key will return the same account
    await cdp.solana.createAccount({ idempotencyKey });
  • Gets a Solana account by its address.

    Parameters

    • options: GetAccountOptions

      Parameters for getting the Solana account. Either address or name must be provided. If both are provided, lookup will be done by address and name will be ignored.

      Options for getting a Solana account.

      • Optionaladdress?: string

        The address of the account.

      • Optionalname?: string

        The name of the account.

    Returns Promise<SolanaAccount>

    A promise that resolves to the account.

             const account = await cdp.solana.getAccount({
    address: "1234567890123456789012345678901234567890",
    });
             const account = await cdp.solana.getAccount({
    name: "MyAccount",
    });
  • Lists all Solana accounts.

    Parameters

    • options: ListAccountsOptions = {}

      Parameters for listing the Solana accounts.

      Options for listing Solana accounts.

      • OptionalpageSize?: number

        The page size.

      • OptionalpageToken?: string

        The page token.

    Returns Promise<ListAccountsResult>

    A promise that resolves to an array of Solana account instances.

             const accounts = await cdp.solana.listAccounts();
             let page = await cdp.solana.listAccounts();

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

    page.accounts.forEach(account => console.log(account));
    ```
    }
  • Requests funds from a Solana faucet.

    Parameters

    • options: RequestFaucetOptions

      Parameters for requesting funds from the Solana faucet.

      Options for requesting funds from a Solana faucet.

      • address: string

        The address of the account.

      • OptionalidempotencyKey?: string

        The idempotency key.

      • token: "usdc" | "sol"

        The token to request funds for.

    Returns Promise<SignatureResult>

    A promise that resolves to the transaction signature.

             const signature = await cdp.solana.requestFaucet({
    address: "1234567890123456789012345678901234567890",
    token: "sol",
    });
  • Signs a message.

    Parameters

    • options: SignMessageOptions

      Parameters for signing the message.

      Options for signing a Solana message.

      • address: string

        The address of the account.

      • OptionalidempotencyKey?: string

        The idempotency key.

      • message: string

        The message to sign.

    Returns Promise<SignatureResult>

    A promise that resolves to the signature.

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

    // When you want to sign a message, you can do so by address
    const signature = await cdp.solana.signMessage({
    address: account.address,
    message: "Hello, world!",
    });
  • Signs a transaction.

    Parameters

    • options: SignTransactionOptions

      Parameters for signing the transaction.

      Options for signing a Solana transaction.

      • address: string

        The address of the account.

      • OptionalidempotencyKey?: string

        The idempotency key.

      • transaction: string

        The base64 encoded transaction to sign.

    Returns Promise<SignatureResult>

    A promise that resolves to the signature.

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

    // Add your transaction instructions here
    const transaction = new Transaction()

    // Make sure to set requireAllSignatures to false, since signing will be done through the API
    const serializedTransaction = transaction.serialize({
    requireAllSignatures: false,
    });

    // Base64 encode the serialized transaction
    const transaction = Buffer.from(serializedTransaction).toString("base64");

    // When you want to sign a transaction, you can do so by address and base64 encoded transaction
    const signature = await cdp.solana.signTransaction({
    address: account.address,
    transaction,
    });