CDP SDK TypeScript - v1.31.0
    Preparing search index...

    Type Alias AccountActions

    type AccountActions = {
        requestFaucet: (
            options: Omit<RequestFaucetOptions, "address">,
        ) => Promise<SignatureResult>;
        signMessage: (
            options: Omit<SignMessageOptions, "address">,
        ) => Promise<SignatureResult>;
        signTransaction: (
            options: Omit<SignTransactionOptions, "address">,
        ) => Promise<SignTransactionResult>;
        sendTransaction: (
            options: Omit<SendTransactionOptions, "address">,
        ) => Promise<SendTransactionResult>;
        transfer: (
            options: Omit<TransferOptions, "from">,
        ) => Promise<SignatureResult>;
        quoteFund: (
            options: Omit<SolanaQuoteFundOptions, "address">,
        ) => Promise<SolanaQuote>;
        fund: (
            options: Omit<SolanaFundOptions, "address">,
        ) => Promise<FundOperationResult>;
        waitForFundOperationReceipt(
            options: WaitForFundOperationOptions,
        ): Promise<WaitForFundOperationResult>;
    }
    Index

    Properties

    requestFaucet: (
        options: Omit<RequestFaucetOptions, "address">,
    ) => Promise<SignatureResult>

    Requests funds from a Solana faucet.

    Type declaration

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

    // Request funds from the Solana faucet
    const result = await account.requestFaucet({
    token: "sol",
    });
    signMessage: (
        options: Omit<SignMessageOptions, "address">,
    ) => Promise<SignatureResult>

    Signs a message.

    Type declaration

      • (options: Omit<SignMessageOptions, "address">): Promise<SignatureResult>
      • Parameters

        • options: Omit<SignMessageOptions, "address">

          Parameters for signing the message.

          • address

            The address to sign the message for.

          • message

            The message to sign.

          • idempotencyKey

            An idempotency key.

        Returns Promise<SignatureResult>

        A promise that resolves to the signature.

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

    // Sign a message
    const { signature } = await account.signMessage({
    message: "Hello, world!",
    });
    signTransaction: (
        options: Omit<SignTransactionOptions, "address">,
    ) => Promise<SignTransactionResult>

    Signs a transaction.

    Type declaration

      • (
            options: Omit<SignTransactionOptions, "address">,
        ): Promise<SignTransactionResult>
      • Parameters

        • options: Omit<SignTransactionOptions, "address">

          Parameters for signing the transaction.

          • address

            The address to sign the transaction for.

          • transaction

            The transaction to sign.

          • idempotencyKey

            An idempotency key.

        Returns Promise<SignTransactionResult>

        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 { signedTransaction } = await account.signTransaction({
    transaction,
    });
    sendTransaction: (
        options: Omit<SendTransactionOptions, "address">,
    ) => Promise<SendTransactionResult>

    Sends a transaction.

    Type declaration

      • (
            options: Omit<SendTransactionOptions, "address">,
        ): Promise<SendTransactionResult>
      • Parameters

        • options: Omit<SendTransactionOptions, "address">

          Parameters for sending the transaction.

          • address

            The address to send the transaction for.

          • transaction

            The transaction to send.

          • idempotencyKey

            An idempotency key.

        Returns Promise<SendTransactionResult>

        A promise that resolves to the transaction 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 { transactionSignature } = await account.sendTransaction({
    transaction,
    });
    transfer: (options: Omit<TransferOptions, "from">) => Promise<SignatureResult>

    Transfers SOL or SPL tokens between accounts

    Type declaration

      • (options: Omit<TransferOptions, "from">): Promise<SignatureResult>
      • Parameters

        • options: Omit<TransferOptions, "from">

          Parameters for the transfer.

          • to

            The base58 encoded Solana address of the destination account.

          • token

            The token to transfer ("sol" or "usdc"), or mint address of the SPL token to transfer.

          • amount

            The amount to transfer in atomic units of the token. For example, 0.01 * LAMPORTS_PER_SOL would transfer 0.01 SOL.

          • network

            The network identifier to use, or a Solana Connection object.

        Returns Promise<SignatureResult>

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

    import { LAMPORTS_PER_SOL } from "@solana/web3.js";

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

    const { signature } = await account.transfer({
    token: "sol",
    amount: 5 * LAMPORTS_PER_SOL,
    to: "3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE",
    network: "devnet",
    });
    quoteFund: (
        options: Omit<SolanaQuoteFundOptions, "address">,
    ) => Promise<SolanaQuote>

    Gets a quote to fund a Solana account.

    Type declaration

      • (options: Omit<SolanaQuoteFundOptions, "address">): Promise<SolanaQuote>
      • Parameters

        • options: Omit<SolanaQuoteFundOptions, "address">

          The options for the quote fund.

          • token

            The token to fund the account with.

          • amount

            The amount of the token to fund represented as an atomic unit. It's common to use parseUnits utils from viem to convert to atomic units. Otherwise, you can pass atomic units directly.

        Returns Promise<SolanaQuote>

        A promise that resolves to a Quote object containing details about the funding operation.

    const quote = await account.quoteFund({
    token: "usdc",
    amount: 1000000n,
    });
    fund: (
        options: Omit<SolanaFundOptions, "address">,
    ) => Promise<FundOperationResult>

    Funds a Solana account with the specified token amount.

    Type declaration

      • (options: Omit<SolanaFundOptions, "address">): Promise<FundOperationResult>
      • Parameters

        • options: Omit<SolanaFundOptions, "address">

          The options for the fund operation.

          • token

            The token to fund the account with (e.g., 'usdc').

          • amount

            The amount of the token to fund represented as an atomic unit. It's common to use parseUnits utils from viem to convert to atomic units. Otherwise, you can pass atomic units directly.

        Returns Promise<FundOperationResult>

        A promise that resolves to the fund operation result containing the transfer details.

    const fundOperation = await account.fund({
    token: "usdc",
    amount: 1000000n,
    });

    Methods

    • Waits for a fund operation to complete and returns the transfer receipt.

      Parameters

      • options: WaitForFundOperationOptions

        The options for the wait for fund operation.

        • transferId

          The ID of the transfer to wait for.

      Returns Promise<WaitForFundOperationResult>

      A promise that resolves to the completed transfer receipt containing details about the funding operation.

      const completedTransfer = await account.waitForFundOperationReceipt({
      transferId: "transfer_123",
      });