A comprehensive demonstration of the Coinbase Developer Platform (CDP) SDK for Python, showcasing wallet creation, transaction management, policies, gas sponsorship, and security best practices.
This demo application demonstrates:
- SDK Setup - Secure configuration with environment variables
- Account Management - Creating new and importing existing Ethereum accounts
- Transactions - Sending transactions and fetching balances
- Policy Enforcement - Attaching policies with failing/successful transaction examples
- Gas Sponsorship - Enabling gasless transactions using Smart Accounts
- Secret Rotation - Production security practices for credential management
- Python 3.8 or higher
- CDP API credentials (API Key ID, API Key Secret, Wallet Secret)
- Access to Base Sepolia testnet
-
Clone this repository or download the files
-
Install dependencies:
pip install -r requirements.txt- Create a
.envfile with your CDP credentials:
CDP_API_KEY_ID=your_api_key_id_here
CDP_API_KEY_SECRET=your_api_key_secret_here
CDP_WALLET_SECRET=your_wallet_secret_here
# Optional: Provide your own private key to import (without 0x prefix)
# If not provided, a temporary key will be generated for demonstration
IMPORT_PRIVATE_KEY=your_private_key_here- Visit the CDP Portal
- Create a new project or select an existing one
- Navigate to Settings > API Keys
- Click Create API Key
- Download the credentials and add them to your
.envfile
Run the demo application:
python main.pyThe application will execute all demonstrations in sequence:
- Loads environment variables securely
- Initializes the CDP client
- Verifies credentials
- Creates a new Ethereum account
- Imports a real private key (from
IMPORT_PRIVATE_KEYenv variable or generates one) - Verifies imported address matches expected address
- Shows account addresses and metadata
- Requests testnet ETH from the CDP faucet
- Fetches account balances
- Sends a test transaction
- Shows updated balances after transaction
- Explains policy concepts
- Demonstrates a failing transaction (exceeds policy limits)
- Shows a successful transaction (within policy limits)
- Provides guidance on implementing real policies
- Creates a Smart Account (ERC-4337)
- Demonstrates gasless transactions
- Shows how paymasters cover gas fees
- Explains user operation flow
- Explains secret rotation importance
- Shows best practices for credential management
- Provides step-by-step rotation instructions
- Displays current secret status (masked)
wallet-python/
├── main.py # Main demo application
├── requirements.txt # Python dependencies
├── .env # Environment variables (not in git)
├── .gitignore # Git ignore rules
└── README.md # This file
- Private/public key pairs for signing transactions
- Generated and stored in CDP's Trusted Execution Environment (TEE)
- Same address works across all EVM-compatible networks
- ERC-4337 compliant smart contract wallets
- Enable account abstraction features
- Support gasless transactions via paymasters
- Allow batched operations
- Control transaction permissions
- Set spending limits and allowed recipients
- Enforce security rules at the protocol level
- Managed via CDP Portal
- Paymasters pay gas fees on behalf of users
- Users don't need native tokens for transactions
- Improves user experience significantly
- Requires Smart Account setup
This demo uses Base Sepolia testnet, but CDP supports:
- Ethereum (Mainnet & Sepolia)
- Base (Mainnet & Sepolia)
- Polygon (Mainnet & Amoy)
- Arbitrum (Mainnet & Sepolia)
- Optimism (Mainnet & Sepolia)
- Avalanche (Mainnet & Fuji)
- Solana (Mainnet & Devnet)
- Never commit
.envfiles - Use.gitignore - Rotate secrets regularly - Every 90 days minimum
- Use secret management services - AWS Secrets Manager, HashiCorp Vault, etc.
- Monitor API usage - Check CDP Portal for unusual activity
- Implement policies - Restrict transaction permissions
- Test on testnet first - Always verify on testnet before mainnet
- Check if you've exceeded daily limits
- Manually fund accounts via Base Sepolia Faucet
- Ensure account has sufficient balance
- Verify network is correct (base-sepolia)
- Check gas prices aren't too low
- Verify all environment variables are set
- Check API key hasn't expired
- Ensure Wallet Secret is correctly formatted
Key CDP SDK methods used in this demo:
# Client initialization
cdp = CdpClient()
# Account management
account = await cdp.evm.create_account(name="my-account")
imported = await cdp.evm.import_account(private_key="0x...")
# Faucet
faucet = await cdp.evm.request_faucet(address="0x...", network="base-sepolia", token="eth")
# Balances
balances = await cdp.evm.list_token_balances(address="0x...", network="base-sepolia")
# Transactions
tx = await cdp.evm.send_transaction(
address="0x...",
network="base-sepolia",
to="0x...",
value="1000000000000000"
)
# Smart Accounts
smart_account = await cdp.evm.create_smart_account(
owner_address="0x...",
network="base-sepolia",
name="my-smart-account"
)
# User Operations (gasless)
user_op = await cdp.evm.send_user_operation(
smart_account_address="0x...",
network="base-sepolia",
calls=[{"to": "0x...", "value": "1000", "data": "0x"}]
)This demo is provided as-is for educational purposes.