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

    The namespace containing all Solana methods.

    Implements

    Index

    Constructors

    Methods

    • Creates a new Solana account.

      Parameters

      • options: CreateAccountOptions = {}

        Parameters for creating the Solana account.

        Options for creating a Solana account.

        • Optionalname?: string

          The name of the account.

        • OptionalaccountPolicy?: string

          The policy ID to apply to the account.

        • OptionalidempotencyKey?: string

          The idempotency key.

      Returns Promise<
          {
              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>;
          },
      >

      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 });
    • Exports a CDP Solana account's private key. It is important to store the private key in a secure place after it's exported.

      Parameters

      • options: ExportAccountOptions

        Parameters for exporting the Solana account.

        Options for exporting a Solana account.

        • Optionaladdress?: string

          The address of the account.

        • Optionalname?: string

          The name of the account.

        • OptionalidempotencyKey?: string

          The idempotency key.

      Returns Promise<string>

      A promise that resolves to the exported account's full 64-byte private key as a base58 encoded string.

      const privateKey = await cdp.solana.exportAccount({
      address: "1234567890123456789012345678901234567890",
      });
      const privateKey = await cdp.solana.exportAccount({
      name: "MyAccount",
      });
    • Imports a Solana account using a private key. The private key will be encrypted before being stored securely.

      Parameters

      • options: ImportAccountOptions

        Parameters for importing the Solana account.

        Options for importing a Solana account.

        • OptionalencryptionPublicKey?: string

          The public RSA key used to encrypt the private key when importing a Solana account.

        • Optionalname?: string

          The name of the account.

        • OptionalidempotencyKey?: string

          The idempotency key.

        • privateKey: string | Uint8Array<ArrayBufferLike>

          The private key of the account - can be a base58 encoded string or raw bytes.

      Returns Promise<
          {
              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>;
          },
      >

      A promise that resolves to the imported account.

               const account = await cdp.solana.importAccount({
      privateKey: "3Kzjw8qSxx8bQkV7EHrVFWYiPyNLbBVxtVe1Q5h2zKZY8DdcuT2dKxyz9kU5vQrP",
      });
               const account = await cdp.solana.importAccount({
      privateKey: "3Kzjw8qSxx8bQkV7EHrVFWYiPyNLbBVxtVe1Q5h2zKZY8DdcuT2dKxyz9kU5vQrP",
      name: "ImportedAccount",
      });
               const idempotencyKey = uuidv4();

      const account = await cdp.solana.importAccount({
      privateKey: "3Kzjw8qSxx8bQkV7EHrVFWYiPyNLbBVxtVe1Q5h2zKZY8DdcuT2dKxyz9kU5vQrP",
      name: "ImportedAccount",
      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<
          {
              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>;
          },
      >

      A promise that resolves to the account.

               const account = await cdp.solana.getAccount({
      address: "1234567890123456789012345678901234567890",
      });
               const account = await cdp.solana.getAccount({
      name: "MyAccount",
      });
    • Gets a Solana account by its address.

      Parameters

      • options: GetOrCreateAccountOptions

        Parameters for getting or creating the Solana account.

        Options for getting a Solana account.

        • name: string

          The name of the account.

      Returns Promise<
          {
              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>;
          },
      >

      A promise that resolves to the account.

      const account = await cdp.solana.getOrCreateAccount({
      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.

        • token: "usdc" | "sol"

          The token to request funds for.

        • OptionalidempotencyKey?: string

          The idempotency key.

      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.

        • message: string

          The message to sign.

        • OptionalidempotencyKey?: string

          The idempotency key.

      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.

        • transaction: string

          The base64 encoded transaction to sign.

        • OptionalidempotencyKey?: string

          The 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 signature = await cdp.solana.signTransaction({
      address: account.address,
      transaction,
      });
    • Updates a CDP Solana account.

      Parameters

      • Optionaloptions: UpdateSolanaAccountOptions

        Optional parameters for creating the account.

        Options for creating a SOL server account.

        • address: string

          The address of the account.

        • update: UpdateSolanaAccountBody

          The updates to apply to the account

        • OptionalidempotencyKey?: string

          The idempotency key.

      Returns Promise<
          {
              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>;
          },
      >

      A promise that resolves to the updated account.

               const account = await cdp.sol.updateAccount({ address: "...", update: { name: "New Name" } });
               const account = await cdp.sol.updateAccount({ address: "...", update: { accountPolicy: "73bcaeeb-d7af-4615-b064-42b5fe83a31e" } });
               const idempotencyKey = uuidv4();

      // First call
      await cdp.sol.updateAccount({
      address: "0x...",
      update: { accountPolicy: "73bcaeeb-d7af-4615-b064-42b5fe83a31e" },
      idempotencyKey,
      });

      // Second call with the same idempotency key will not update
      await cdp.sol.updateAccount({
      address: '0x...',
      update: { name: "" },
      idempotencyKey,
      });
    • Sends a Solana transaction using the Coinbase API.

      Parameters

      • options: SendTransactionOptions

        Parameters for sending the Solana transaction.

        Options for sending a Solana transaction.

        • network: SendSolanaTransactionBodyNetwork

          The network to send the transaction to.

        • transaction: string

          The base64 encoded transaction to send.

        • OptionalidempotencyKey?: string

          The idempotency key.

      Returns Promise<SendTransactionResult>

      A promise that resolves to the transaction result.

      const signature = await cdp.solana.sendTransaction({
      network: "solana-devnet",
      transaction: "...",
      });
    • Lists the token balances for a Solana account.

      Parameters

      • options: ListTokenBalancesOptions

        Parameters for listing the Solana token balances.

        Options for listing Solana token balances.

        • address: string

          The address of the account.

        • Optionalnetwork?: ListSolanaTokenBalancesNetwork

          The network to list token balances for.

        • OptionalpageSize?: number

          The page size.

        • OptionalpageToken?: string

          The page token.

      Returns Promise<ListTokenBalancesResult>

      A promise that resolves to an array of Solana token balance instances.

      const balances = await cdp.solana.listTokenBalances({ address: "...", network: "solana-devnet" });