CDP Python SDK
Project description
CDP Python SDK
The CDP Python SDK enables the simple integration of crypto into your app. By calling Coinbase's CDP APIs, the SDK allows you to provision crypto wallets, send crypto into/out of those wallets, track wallet balances, and trade crypto from one asset into another.
CDP SDK v0 is a pre-alpha release, which means that the APIs and SDK methods are subject to change. We will continuously release updates to support new capabilities and improve the developer experience.
Documentation
Requirements
- Python 3.10+
Checking Python Version
Before using the SDK, ensure that you have the correct version of Python installed. The SDK requires Python 3.10 or higher. You can check your Python version by running the following code:
python --version
If you need to upgrade your Python version, you can download and install the latest version of Python from the official Python website.
Installation
pip install cdp-sdk
Starting a Python REPL
To start a Python REPL:
python
Creating a Wallet
To start, create a CDP API key. Then, initialize the CDP SDK by passing your API key name and API key's private key via the configure
method:
from cdp import *
api_key_name = "Copy your API key name here."
# Ensure that you are using double-quotes here.
api_key_private_key = "Copy your 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 API key, downloaded from the CDP portal.
Cdp.configure_from_json("~/Downloads/cdp_api_key.json")
print("CDP SDK has been successfully configured from JSON file.")
This will allow you to authenticate with the Platform APIs.
If you are using a CDP Server-Signer to manage your private keys, enable it with
Cdp.use_server_signer = True
Now create a wallet. Wallets are created with a single default address.
# Create a wallet with one address by default.
wallet1 = Wallet.create()
Wallets come with a single default address, accessible via default_address
:
# A wallet has a default address.
address = wallet1.default_address
Funding a Wallet
Wallets do not have funds on them to start. For Base Sepolia testnet, we provide a faucet
method to fund your wallet with
testnet ETH. You are allowed one faucet claim per 24-hour window.
# Fund the wallet with a faucet transaction.
faucet_tx = wallet1.faucet()
print(f"Faucet transaction successfully completed: {faucet_tx}")
Transferring Funds
See Transfers for more information.
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 uses the transfer
function to send testnet ETH from the first wallet to
the second:
# Create a new wallet wallet2 to transfer funds to.
wallet2 = Wallet.create()
print(f"Wallet successfully created: {wallet2}")
transfer = wallet1.transfer(0.00001, "eth", wallet2).wait()
print(f"Transfer successfully completed: {transfer}")
Gasless USDC Transfers
To transfer USDC without needing to hold ETH for gas, you can use the transfer
method with the gasless
option set to True
.
# Create a new wallet wallet3 to transfer funds to.
wallet3 = Wallet.create()
print(f"Wallet successfully created: {wallet3}")
transfer = wallet1.transfer(0.00001, "usdc", wallet3, gasless=True).wait()
Listing Transfers
# Return list of all transfers. This will paginate and fetch all transfers for the address.
address.transfers()
Trading Funds
See Trades for more information.
wallet = Wallet.create("base-mainnet")
print(f"Wallet successfully created: {wallet}")
print(f"Send `base-mainnet` ETH to wallets default address: {wallet.default_address.address_id}")
trade = wallet.trade(0.00001, "eth", "usdc").wait()
print(f"Trade successfully completed: {trade}")
Listing Trades
# Return list of all trades. This will paginate and fetch all trades for the address.
address.trades()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cdp_sdk-0.0.1.tar.gz
.
File metadata
- Download URL: cdp_sdk-0.0.1.tar.gz
- Upload date:
- Size: 105.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3971d079ba7e5323c921891b9fbe757a8009df6be7616fcba1745b6962570c32 |
|
MD5 | 93b8ddd590c4e3c2c474ec1a497da5d2 |
|
BLAKE2b-256 | 97e0aec97cb5b5dd2503dc4d56e489123d4ef0d6fbdc1640f8898fae9515907d |
File details
Details for the file cdp_sdk-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: cdp_sdk-0.0.1-py3-none-any.whl
- Upload date:
- Size: 227.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6c9cdd0100d26a1d7e462369f0138f8bcf712a31591a123c92a1c79313b3bbe |
|
MD5 | cea27e14f175e0313da7aa4490ca4fa0 |
|
BLAKE2b-256 | f927b9aaf0307fa3e5daf20601b7a99d3c767505e044c7486bce571db7ddd825 |