CDP SDK TypeScript - v1.43.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>;
    }
    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",
    });