Runnable Java examples for the CDP Payments and Custodial Accounts APIs. Each API operation is a command-line program that calls the REST API directly. By default, commands use CDP Sandbox, which never moves real funds.
- JDK 17 or later
- Maven 3.9 or later
- A CDP Sandbox API key with the permissions required by the endpoint
Create and fund a simulated account first by following the Custodial Wallets quickstart.
Download the API key JSON file from the CDP Portal and keep it outside this repository. Then set its path:
export CDP_API_KEY_FILE="$HOME/Downloads/cdp_api_key.json"The scripts support recommended Ed25519 keys and legacy ECDSA keys. Alternatively, set the values directly:
export CDP_KEY_ID='organizations/.../apiKeys/...'
export CDP_KEY_SECRET='base64 Ed25519 secret or ECDSA PEM'CDP_API_KEY_FILE takes precedence when both options are set. See .env.example for all configuration variables.
From the repository root:
make build
make test
make run SCRIPT=accounts.ListAccountsThe final command lists Sandbox accounts and balances. JSON responses are written to stdout; errors and diagnostics are written to stderr.
Use make run with the script name and any command arguments. Run --help on a script to see its path and query options:
make run SCRIPT=accounts.ListAccounts ARGS='--help'
make run SCRIPT=accounts.ListBalances ARGS='--account-id account_123'For write operations, pass exactly one request body source:
make run SCRIPT=accounts.CreateAccount \
ARGS='--body-file examples/requests/create-account.json'Scripts that support retries accept --idempotency-key UUID. If omitted, they generate a UUID v4 and print it to stderr. Every non-2xx API response exits nonzero.
examples/README.md contains a runnable Sandbox command for every account, deposit-destination, transfer, and payment-method endpoint, along with request-body templates and executable wrapper scripts. Replace placeholder resource IDs with values returned by the corresponding list or create command.
Commands target https://sandbox.cdp.coinbase.com/platform by default. To call production explicitly:
export CDP_ENVIRONMENT=productionTo use a custom endpoint, for example in local testing:
export CDP_API_BASE_URL=https://example.test/platformmake format
make lint
make test
make buildTests use a local HTTP server and do not contact CDP.
Apache License 2.0. See LICENSE.