The CDP SDK allows you to create wallets and send funds onchain within minutes.
In this quickstart, you will learn how to create a wallet, fund it with testnet ETH,
transfer funds between wallets, and trade assets.
Make sure that your developer environment satisfies all of the requirements before proceeding through the quickstart.
Node.js 18+
The Coinbase server-side SDK requires Node.js version 18 or higher and npm version 9.7.2 or higher. To view your currently installed versions of Node.js, run the following from the command-line:
Copy
Ask AI
node -vnpm -v
We recommend installing and managing Node.js and npm versions with nvm.
See Installing and Updating in the nvm README for instructions on how to install nvm.
Once nvm has been installed, you can install and use the latest versions of Node.js and npm by running the following commands:
Copy
Ask AI
nvm install node # "node" is an alias for the latest versionnvm use node
Node.js 18+
The Coinbase server-side SDK requires Node.js version 18 or higher and npm version 9.7.2 or higher. To view your currently installed versions of Node.js, run the following from the command-line:
Copy
Ask AI
node -vnpm -v
We recommend installing and managing Node.js and npm versions with nvm.
See Installing and Updating in the nvm README for instructions on how to install nvm.
Once nvm has been installed, you can install and use the latest versions of Node.js and npm by running the following commands:
Copy
Ask AI
nvm install node # "node" is an alias for the latest versionnvm use node
Python 3.10+
Before using the SDK, ensure that you have the correct version of Python installed and the pip package manager. The SDK requires Python 3.10 or higher. You can check your Python version and pip installation by running the following code:
Copy
Ask AI
python --versionpip --version
If you need to upgrade your Python version, you can download and install the latest version of Python from the official Python website. For pip, refer to the official pip documentation for installation instructions.
Initialize the CDP SDK by passing your downloaded API key file
Create a new Developer-Managed (1-of-1) wallet
This quickstart creates wallets on Base Sepolia testnet. You can create wallets across various EVM networks, including Base, Ethereum L1, and Polygon.
Initialize the SDK by passing your API key information:
index.js
Copy
Ask AI
import { Coinbase, Wallet } from "@coinbase/coinbase-sdk";const apiKeyName = "Copy your secret API key name here."const apiKeyPrivateKey = "Copy your secret API key's private key here."Coinbase.configure(apiKeyName, apiKeyPrivateKey)
Another way to initialize the SDK is by sourcing the API key from the JSON file that contains your secret API key, downloaded from the CDP portal:
index.js
Copy
Ask AI
let coinbase = Coinbase.configureFromJson({ filePath: '~/Downloads/cdp_api_key.json' });
Now create a wallet:
index.js
Copy
Ask AI
// Create a new Walletlet wallet = await Wallet.create();console.log(`Wallet successfully created: `, wallet.toString());// Wallets are not saved locally by default. Refer to the Wallets concept for more information.
Wallets are initialized with a single default Address, accessible via getDefaultAddress:
index.js
Copy
Ask AI
let address = await wallet.getDefaultAddress();console.log(`Default address for the wallet: `, address.toString());
Initialize the SDK by passing your API key information:
index.js
Copy
Ask AI
import { Coinbase, Wallet } from "@coinbase/coinbase-sdk";const apiKeyName = "Copy your secret API key name here."const apiKeyPrivateKey = "Copy your secret API key's private key here."Coinbase.configure(apiKeyName, apiKeyPrivateKey)
Another way to initialize the SDK is by sourcing the API key from the JSON file that contains your secret API key, downloaded from the CDP portal:
index.js
Copy
Ask AI
let coinbase = Coinbase.configureFromJson({ filePath: '~/Downloads/cdp_api_key.json' });
Now create a wallet:
index.js
Copy
Ask AI
// Create a new Walletlet wallet = await Wallet.create();console.log(`Wallet successfully created: `, wallet.toString());// Wallets are not saved locally by default. Refer to the Wallets concept for more information.
Wallets are initialized with a single default Address, accessible via getDefaultAddress:
index.js
Copy
Ask AI
let address = await wallet.getDefaultAddress();console.log(`Default address for the wallet: `, address.toString());
Initialize the SDK by passing your API key information:
Copy
Ask AI
api_key_name = "Copy your secret API key name here."api_key_private_key = "Copy your secret API key's private key here."Cdp.configure(api_key_name, api_key_private_key)print("CDP SDK has been successfully configured with CDP API key.")
Another way to initialize the SDK is by sourcing the API key from the JSON file that contains your secret API key, downloaded from the CDP portal:
Copy
Ask AI
Cdp.configure_from_json("~/Downloads/cdp_api_key.json")print("CDP SDK has been successfully configured from JSON file.")
Now create a wallet:
Copy
Ask AI
# Create a new wallet.wallet = Wallet.create()# Wallets are not saved locally by default. Refer to the Wallets concept for more information.
Wallets are initialized with a single default address, accessible via default_address:
Copy
Ask AI
address = wallet.default_addressprint(f"Default address for the wallet: {address.address_id}")
This quickstart creates wallets on Base Sepolia testnet. You can create wallets across various EVM networks, including Base, Ethereum L1, and Polygon.
Initialize the SDK by passing your API key information:
index.js
Copy
Ask AI
import { Coinbase, Wallet } from "@coinbase/coinbase-sdk";const apiKeyName = "Copy your secret API key name here."const apiKeyPrivateKey = "Copy your secret API key's private key here."Coinbase.configure(apiKeyName, apiKeyPrivateKey)
Another way to initialize the SDK is by sourcing the API key from the JSON file that contains your secret API key, downloaded from the CDP portal:
index.js
Copy
Ask AI
let coinbase = Coinbase.configureFromJson({ filePath: '~/Downloads/cdp_api_key.json' });
Now import your wallet:
index.js
Copy
Ask AI
// Import your Wallet into CDP using your BIP-39 mnemonic seed phrase.// NOTE 1: For security reasons, we recommend storing your seed phrase in an environment variable.// NOTE 2: Your wallet's seed and seed phrase will not leave your device.let wallet = await Wallet.import({ mnemonicPhrase: process.env.MNEMONIC_PHRASE });console.log(`Wallet successfully created: `, wallet.toString());// Wallets are not saved locally by default. Refer to the Wallets concept for more information.
Wallets are initialized with a single default Address, accessible via getDefaultAddress:
index.js
Copy
Ask AI
let address = await wallet.getDefaultAddress();console.log(`Default address for the wallet: `, address.toString());
Initialize the SDK by passing your API key information:
index.js
Copy
Ask AI
import { Coinbase, Wallet } from "@coinbase/coinbase-sdk";const apiKeyName = "Copy your secret API key name here."const apiKeyPrivateKey = "Copy your secret API key's private key here."Coinbase.configure(apiKeyName, apiKeyPrivateKey)
Another way to initialize the SDK is by sourcing the API key from the JSON file that contains your secret API key, downloaded from the CDP portal:
index.js
Copy
Ask AI
let coinbase = Coinbase.configureFromJson({ filePath: '~/Downloads/cdp_api_key.json' });
Now import your wallet:
index.js
Copy
Ask AI
// Import your Wallet into CDP using your BIP-39 mnemonic seed phrase.// NOTE 1: For security reasons, we recommend storing your seed phrase in an environment variable.// NOTE 2: Your wallet's seed and seed phrase will not leave your device.let wallet = await Wallet.import({ mnemonicPhrase: process.env.MNEMONIC_PHRASE });console.log(`Wallet successfully created: `, wallet.toString());// Wallets are not saved locally by default. Refer to the Wallets concept for more information.
Wallets are initialized with a single default Address, accessible via getDefaultAddress:
index.js
Copy
Ask AI
let address = await wallet.getDefaultAddress();console.log(`Default address for the wallet: `, address.toString());
Initialize the SDK by passing your API key information:
Copy
Ask AI
api_key_name = "Copy your secret API key name here."api_key_private_key = "Copy your secret API key's private key here."Cdp.configure(api_key_name, api_key_private_key)print("CDP SDK has been successfully configured with CDP API key.")
Another way to initialize the SDK is by sourcing the API key from the JSON file that contains your secret API key, downloaded from the CDP portal:
Copy
Ask AI
Cdp.configure_from_json("~/Downloads/cdp_api_key.json")print("CDP SDK has been successfully configured from JSON file.")
Now import your wallet:
Copy
Ask AI
# Import your Wallet into CDP using your BIP-39 mnemonic seed phrase.# NOTE 1: For security reasons, we recommend storing your seed phrase in an environment variable.# NOTE 2: Your wallet's seed and seed phrase will not leave your device.imported_wallet = Wallet.import_wallet(MnemonicSeedPhrase(os.getenv("MNEMONIC_PHRASE")))# Wallets are not saved locally by default. Refer to the Wallets concept for more information.
Wallets are initialized with a single default address, accessible via default_address:
Copy
Ask AI
address = wallet.default_addressprint(f"Default address for the wallet: {address.address_id}")
Once initialized, your imported wallet should be stored as a Wallet data object, for easy re-instantiation. Refer to Persisting a wallet section for more information.
Wallets do not have funds on them to start. For Base Sepolia and Ethereum Sepolia testnets, we provide a faucet method to fund your wallet with
testnet ETH.
Copy
Ask AI
const faucetTransaction = await wallet.faucet();// Wait for transaction to land on-chain.await faucetTransaction.wait();console.log(`Faucet transaction completed successfully: `, faucetTransaction.toString());
Now that your faucet transaction has successfully completed, you can send the funds in your wallet to another wallet.
The code below creates another wallet, and sends testnet ETH from the first wallet to the second:
Creating multiple transactions simultaneously can lead to failures.
All transfers, excluding gasless transfers, do not support concurrent transactions. We recommend running sequential calls and waiting for the previous transaction to confirm before continuing.
let anotherWallet = await Wallet.create();console.log(`Second Wallet successfully created: `, anotherWallet.toString());const transfer = await wallet.createTransfer({amount: 0.00001,assetId: Coinbase.assets.Eth,destination: anotherWallet,});// Wait for the transfer to settle.await transfer.wait()// Check if the transfer successfully completed on-chain.if (transfer.getStatus() === 'complete') {console.log(`Transfer successfully completed: `, transfer.toString());} else {console.error('Transfer failed on-chain: ', transfer.toString());}
On base-mainnet you can trade between different assets from your wallet. Since trading is only supported on mainnet wallets, wallet should be funded with real assets before trading. The code below creates a wallet and trades some ETH to USDC and then all of the USDC to WETH:
Refer to trade.js for a complete example of trading assets.
trade_assets.js
Copy
Ask AI
import { Coinbase, Wallet } from "@coinbase/coinbase-sdk";let coinbase = Coinbase.configureFromJson({ filePath: '~/Downloads/cdp_api_key.json' });// Create a Wallet on base-mainnet to trade assets with.let wallet = await Wallet.create({ networkId: Coinbase.networks.BaseMainnet });// Fund the Wallet's default Address with ETH from an external source.// Trade 0.00001 ETH to USDC.let trade = await wallet.createTrade({ amount: 0.00001, fromAssetId: Coinbase.assets.Eth, toAssetId: Coinbase.assets.Usdc});await trade.wait();if (trade.getStatus() === 'complete') { console.log(`Trade successfully completed: `, trade.toString());} else { console.log(`Trade failed on-chain: `, trade.toString());}// Trade the wallet's full balance of USDC to WETH.let trade2 = await wallet.createTrade({ amount: wallet.getBalance(Coinbase.assets.Usdc), fromAssetId: Coinbase.assets.Usdc, toAssetId: Coinbase.assets.Weth,});await trade2.wait();if (trade2.getStatus() === "complete") { console.log(`Trade successfully completed: `, trade2.toString());} else { console.log(`Trade failed on-chain: `, trade2.toString());}
# Create a wallet on `base-mainnet` to trade assets with.wallet = Wallet.create(network_id="base-mainnet")print("Wallet successfully created: {wallet}")# Fund wallet's default address with ETH from an external source.# Trade 0.00001 ETH to USDCtrade = wallet.trade(0.00001, "eth", "usdc").wait()if trade.status is Transaction.Status.COMPLETE: print(f"Trade successfully completed: {trade}")else: print(f"Trade failed on-chain: {trade}")# Trade the wallet's full balance of USDC to WETHtrade2 = wallet.trade(wallet.balance("usdc"), "usdc", "weth").wait()if trade2.status is Transaction.Status.COMPLETE: print(f"Second trade successfully completed: {trade2}")else: print(f"Second trade failed on-chain: {trade}")