https://github.com/coinbase-samples/prime-sdk-go
Sample Go SDK for the Coinbase Prime REST APIs
https://github.com/coinbase-samples/prime-sdk-go
Last synced: 5 months ago
JSON representation
Sample Go SDK for the Coinbase Prime REST APIs
- Host: GitHub
- URL: https://github.com/coinbase-samples/prime-sdk-go
- Owner: coinbase-samples
- License: apache-2.0
- Created: 2023-04-27T03:46:29.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2026-01-21T19:53:25.000Z (5 months ago)
- Last Synced: 2026-01-22T08:11:32.080Z (5 months ago)
- Language: Go
- Homepage: https://docs.cdp.coinbase.com/prime/docs/rest-requests
- Size: 238 KB
- Stars: 23
- Watchers: 5
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Prime Go SDK README
[](https://godoc.org/github.com/coinbase-samples/prime-sdk-go)
[](https://goreportcard.com/report/coinbase-samples/prime-sdk-go)
## Overview
The *Prime Go SDK* is a sample libary that demonstrates the structure of a [Coinbase Prime](https://prime.coinbase.com/) driver for
the [REST APIs](https://docs.cloud.coinbase.com/prime/reference).
## License
The *Prime Go SDK* sample library is free and open source and released under the [Apache License, Version 2.0](LICENSE).
The application and code are only available for demonstration purposes.
## Usage
To use the *Prime Go SDK*, initialize the [Credentials](credentials.go) struct and create a new client. The Credentials struct is JSON
enabled. Ensure that Prime API credentials are stored in a secure manner.
```
primeCredentials, err := credentials.ReadEnvCredentials("PRIME_CREDENTIALS")
if err != nil {
log.Fatalf("unable to load prime credentials: %v", err)
}
httpClient, err := client.DefaultHttpClient()
if err != nil {
log.Fatalf("unable to load default http client: %v", err)
}
client := client.NewRestClient(primeCredentials, httpClient)
```
The credentials.ReadEnvCredentials is a convenience function to read the credentials from an environment variable and deserialize the JSON structure. Use credentials.UnmarshalCredentials,
if pulled from a different source. The JSON format expected by both is:
```
{
"accessKey": "",
"passphrase": "",
"signingKey": "",
"portfolioId": "",
"svcAccountId": "",
"entityId": ""
}
```
Coinbase Prime API credentials can be created in the Prime web console under Settings -> APIs. Entity ID can be retrieved by calling [Get Portfolio](https://docs.cdp.coinbase.com/prime/reference/primerestapi_getportfolio).
Once the client is initialized, instantiate a service to make the desired call. For example, to list portfolios, create the service, pass in the request object, check for an error, and if nil, process the response.
```
service := portfolios.NewPortfoliosService(client)
response, err := service.ListPortfolios(ctx, &portfolios.ListPortfoliosRequest{})
```
## Build
To build the sample library, ensure that [Go](https://go.dev/) 1.19+ is installed and then run:
```bash
go build ./...
```