Skip to content

Repository files navigation

CDP Payments Java Scripts

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.

Quick start

1. Prerequisites

  • 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.

2. Configure a Sandbox API key

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.

3. Build, test, and make your first Sandbox request

From the repository root:

make build
make test
make run SCRIPT=accounts.ListAccounts

The final command lists Sandbox accounts and balances. JSON responses are written to stdout; errors and diagnostics are written to stderr.

Run commands

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 and available endpoints

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.

Configuration

Commands target https://sandbox.cdp.coinbase.com/platform by default. To call production explicitly:

export CDP_ENVIRONMENT=production

To use a custom endpoint, for example in local testing:

export CDP_API_BASE_URL=https://example.test/platform

Development

make format
make lint
make test
make build

Tests use a local HTTP server and do not contact CDP.

License

Apache License 2.0. See LICENSE.

About

CDP Payments Java sample scripts

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages