Package Exports
- @coinbase/cdp-sdk
- @coinbase/cdp-sdk/auth
Readme
Coinbase Developer Platform (CDP) TypeScript SDK
Table of Contents
[!TIP] If you're looking to contribute to the SDK, please see the Contributing Guide.
CDP SDK
This module contains the TypeScript CDP SDK, which is a library that provides a client for interacting with the Coinbase Developer Platform (CDP). It includes a CDP Client for interacting with EVM and Solana APIs to create accounts and send transactions, as well as authentication tools for interacting directly with the CDP APIs.
Installation
npm install @coinbase/cdp-sdkAPI Keys
To start, create a CDP API Key. Save the API Key ID and API Key Secret for use in the SDK. You will also need to create a wallet secret in the Portal to sign transactions.
Usage
Initialization
Load client config from shell
One option is to export your CDP API Key and Wallet Secret as environment variables:
export CDP_API_KEY_NAME="YOUR_API_KEY_ID"
export CDP_API_KEY_SECRET="YOUR_API_KEY_SECRET"
export CDP_WALLET_SECRET="YOUR_WALLET_SECRET"Then, initialize the client:
import { CdpClient } from "@coinbase/cdp-sdk";
const cdp = new CdpClient();Load client config from .env file
Another option is to save your CDP API Key and Wallet Secret in a .env file:
touch .env
echo "CDP_API_KEY_NAME=YOUR_API_KEY_ID" >> .env
echo "CDP_API_KEY_SECRET=YOUR_API_KEY_SECRET" >> .env
echo "CDP_WALLET_SECRET=YOUR_WALLET_SECRET" >> .envThen, load the client config from the .env file:
import { CdpClient } from "@coinbase/cdp-sdk";
import dotenv from "dotenv";
dotenv.config();
const cdp = new CdpClient();Pass the API Key and Wallet Secret to the client
Another option is to directly pass the API Key and Wallet Secret to the client:
const cdp = new CdpClient({
apiKeyId: "YOUR_API_KEY_ID",
apiKeySecret: "YOUR_API_KEY_SECRET",
walletSecret: "YOUR_WALLET_SECRET",
});Creating EVM or Solana accounts
Create an EVM account as follows:
const evmAccount = await cdp.evm.createAccount();Create a Solana account as follows:
const solanaAccount = await cdp.solana.createAccount();Testnet faucet
You can use the faucet function to request testnet ETH or SOL from the CDP.
Request testnet ETH as follows:
const faucetResp = await cdp.evm.requestFaucet({
address: evmAccount.address,
network: "base-sepolia",
token: "eth",
});Request testnet SOL as follows:
const faucetResp = await cdp.solana.requestFaucet({
address: fromAddress,
token: "sol",
});Sending transactions
For EVM, we recommend using viem to send transactions. See the examples. For Solana, we recommend using the @solana/web3.js library to send transactions. See the examples.
EVM Smart Accounts
For EVM, we support Smart Accounts which are account-abstraction (ERC-4337) accounts. Currently there is only support for Base Sepolia and Base Mainnet for Smart Accounts.
Create an EVM account and a smart account as follows:
const evmAccount = await cdp.evm.createAccount();
const smartAccount = await cdp.evm.createSmartAccount({
owner: evmAccount,
});Sending User Operations
const userOperation = await cdp.evm.sendUserOperation({
smartAccount: smartAccount,
network: "base-sepolia",
calls: [
{
to: "0x0000000000000000000000000000000000000000",
value: parseEther("0.000001"),
data: "0x",
},
],
});In Base Sepolia, all user operations are gasless by default. If you'd like to specify a different paymaster, you can do so as follows:
const userOperation = await cdp.sendUserOperation({
smartAccount: smartAccount,
network: "base-sepolia",
calls: [
{
to: "0x0000000000000000000000000000000000000000",
value: parseEther("0"),
data: "0x",
},
],
paymasterUrl: "https://some-paymaster-url.com",
});Authentication tools
This SDK also contains simple tools for authenticating REST API requests to the Coinbase Developer Platform (CDP). See the Auth README for more details.
Error Reporting
This SDK contains error reporting functionality that sends error events to the CDP. If you would like to disable this behavior, you can set the DISABLE_CDP_ERROR_REPORTING environment variable to true.
DISABLE_CDP_ERROR_REPORTING=trueLicense
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For feature requests, feedback, or questions, please reach out to us in the #cdp-sdk channel of the Coinbase Developer Platform Discord.
Security
If you discover a security vulnerability within this SDK, please see our Security Policy for disclosure information.