The Coinbase Prime Java SDK is a sample library that demonstrates the usage of the Coinbase Prime API via its REST APIs.
The Coinbase Prime Java SDK sample library is free and open source and released under the Apache License, Version 2.0.
The application and code are only available for demonstration purposes.
To use the Coinbase Prime Java SDK, initialize the Credentials class and create a new client. The Credentials class is JSON enabled. Ensure that Prime API credentials are stored in a secure manner. This client can then be used to instantiate Coinbase Prime Services. An example using the PortfoliosService is shown below:
public class Main {
public static void main(String[] args) {
String credsStringBlob = System.getenv("COINBASE_PRIME_CREDENTIALS");
ObjectMapper mapper = new ObjectMapper();
try {
CoinbasePrimeCredentials credentials = new CoinbasePrimeCredentials(credsStringBlob);
CoinbasePrimeClient client = new CoinbasePrimeClient(credentials);
String portfolioId = System.getenv("COINBASE_PRIME_PORTFOLIO_ID");
PortfoliosService portfoliosService = PrimeServiceFactory.createPortfoliosService(client);
GetPortfolioByIdResponse portfolioResponse = portfoliosService.getPortfolioById(
new GetPortfolioByIdRequest.Builder()
.portfolioId(portfolioId)
.build());
System.out.println(mapper.writeValueAsString(portfolioResponse));
} catch (Exception e) {
e.printStackTrace(e);
}
}
}The JSON format expected for COINBASE_PRIME_CREDENTIALS is:
{
"accessKey": "",
"passphrase": "",
"signingKey": ""
}
For a full example on using the SDK, see the Main class under the com.coinbase.examples package.
Warning: this does place a market order for a very small amount of ADA. Please ensure that you have the necessary funds in your account before running this code.
The SDK is organized into service interfaces under com.coinbase.prime.*, each wrapping a domain of the Prime REST API. Use PrimeServiceFactory to construct service instances from a CoinbasePrimeClient.
| Service | Package |
|---|---|
ActivitiesService |
com.coinbase.prime.activities |
AddressBookService |
com.coinbase.prime.addressbook |
AdvancedTransferService |
com.coinbase.prime.advancedtransfer |
AllocationsService |
com.coinbase.prime.allocations |
AssetsService |
com.coinbase.prime.assets |
BalancesService |
com.coinbase.prime.balances |
CommissionService |
com.coinbase.prime.commission |
FinancingService |
com.coinbase.prime.financing |
FuturesService |
com.coinbase.prime.futures |
InvoiceService |
com.coinbase.prime.invoice |
OnchainAddressBookService |
com.coinbase.prime.onchainaddressbook |
OrdersService |
com.coinbase.prime.orders |
PaymentMethodsService |
com.coinbase.prime.paymentmethods |
PortfoliosService |
com.coinbase.prime.portfolios |
PositionsService |
com.coinbase.prime.positions |
ProductsService |
com.coinbase.prime.products |
StakingService |
com.coinbase.prime.staking |
TransactionsService |
com.coinbase.prime.transactions |
UsersService |
com.coinbase.prime.users |
WalletsService |
com.coinbase.prime.wallets |
Binaries and dependency information for Maven, Gradle, Ivy and others can be found at the Maven Central Repository
Maven example:
<dependency>
<groupId>com.coinbase.prime</groupId>
<artifactId>coinbase-prime-sdk-java</artifactId>
<version>x.y.z</version>
</dependency>To build the sample library, ensure that Java Development Kit (JDK) 11+ is installed and then run:
mvn clean installThe SDK includes several example classes demonstrating how to use various endpoints.
First, set up your credentials as environment variables:
export COINBASE_PRIME_CREDENTIALS='{"accessKey":"your-access-key","passphrase":"your-passphrase","signingKey":"your-signing-key"}'
export COINBASE_PRIME_PORTFOLIO_ID="your-portfolio-id"mvn exec:java -Dexec.mainClass="com.coinbase.examples.transactions.ListPortfolioTransactions"Note: Make sure the environment variables are exported in your current shell session before running the examples.
Transactions:
com.coinbase.examples.transactions.ListPortfolioTransactions- List portfolio transactions
Wallets:
com.coinbase.examples.wallets.ListPortfolioWallets- List all wallets in a portfoliocom.coinbase.examples.wallets.GetWallet <wallet-id>- Get wallet detailscom.coinbase.examples.wallets.ListWalletAddresses <wallet-id> <network-id>- List addresses for a walletcom.coinbase.examples.wallets.GetWalletDepositInstructions <wallet-id> [deposit-type]- Get deposit instructions (deposit-type: CRYPTO, WIRE, SEN, SWIFT, SEPA)
Other:
com.coinbase.examples.Main- Comprehensive example with multiple API calls
Example Usage:
# List all wallets
mvn exec:java -Dexec.mainClass="com.coinbase.examples.wallets.ListPortfolioWallets"
# Get specific wallet details
mvn exec:java -Dexec.mainClass="com.coinbase.examples.wallets.GetWallet" -Dexec.args="wallet-id-here"
# List wallet addresses
mvn exec:java -Dexec.mainClass="com.coinbase.examples.wallets.ListWalletAddresses" -Dexec.args="wallet-id network-id"
# Get deposit instructions (defaults to CRYPTO)
mvn exec:java -Dexec.mainClass="com.coinbase.examples.wallets.GetWalletDepositInstructions" -Dexec.args="wallet-id"
# Get deposit instructions for WIRE
mvn exec:java -Dexec.mainClass="com.coinbase.examples.wallets.GetWalletDepositInstructions" -Dexec.args="wallet-id WIRE"The SDK tracks the published Prime OpenAPI definition in apiSpec/prime-public-spec.yaml (source of truth for endpoints and schemas). Refresh the committed file from the live spec:
make fetch-specModels, enums, per-operation request/response types, services, and PrimeServiceFactory are hand-maintained to match that spec. Example programs under com.coinbase.examples ship in the same module and compile with mvn compile—keep them in sync when the SDK API changes.
Release history and API changes are documented in CHANGELOG.md.
If you discover a security vulnerability within this SDK, please see our Security Policy for disclosure information.
For non-security bugs and feature requests, use GitHub Issues.