Skip to content

Latest commit

 

History

History

README.md

Coinbase Developer Platform (CDP) Go SDK

Table of Contents

Tip

If you're looking to contribute to the SDK, please see the Contributing Guide.

CDP SDK

This module contains the Go CDP SDK, which is a library that provides a client for interacting with the Coinbase Developer Platform (CDP). It includes a CDP Client for interacting with EVM and Solana APIs to create accounts and send transactions, as well as authentication tools for interacting directly with the CDP APIs.

CAUTION: The Go SDK is an autogenerated client library, and as such, does not have the first-class support that the Typescript and Python SDKs have. We recommend using the Typescript or Python SDKs instead, if at all possible.

Refer to CDP's Unified API Reference for more details on the APIs accessed through this SDK.

Installation

go get github.com/coinbase/cdp-sdk/go

API Keys

To start, create a CDP API Key. Save the API Key ID and API Key Secret for use in the SDK. You will also need to create a wallet secret in the CDP Portal create accounts and sign transactions.

Usage

See the Go examples directory in the CDP SDK repository for runnable end‑to‑end usage examples.

Initialization

You can import the SDK as follows:

cdp "github.com/coinbase/cdp-sdk/go"

Then, initialize the client as follows:

cdp, err := cdp.NewClient(cdp.ClientOptions{
		APIKeyID:     apiKeyName,
		APIKeySecret: apiKeySecret,
		WalletSecret: walletSecret,
	})

EVM accounts

Create an EVM account as follows:

response, err := cdp.CreateEvmAccountWithResponse(
  ctx,
  nil,
  openapi.CreateEvmAccountJSONRequestBody{},
)
if err != nil {
  return "", err
}

if response.StatusCode() != 201 {
  return "", fmt.Errorf("failed to create EVM account: %v", response.Status())
}

Testnet faucet

You can use the faucet function to request testnet ETH or SOL from the CDP.

Request testnet ETH as follows:

response, err := cdp.RequestEvmFaucetWithResponse(
  ctx,
  openapi.RequestEvmFaucetJSONRequestBody{
    Address: evmAddress,
    Network: openapi.RequestEvmFaucetJSONBodyNetwork("base-sepolia"),
    Token:   openapi.RequestEvmFaucetJSONBodyToken("eth"),
  },
)
if err != nil {
  return err
}

if response.StatusCode() != 200 {
  return fmt.Errorf("failed to faucet EVM address: %v", response.Status())
}

Sign an EVM transaction as follows:

toAddress := common.HexToAddress("0x450B2dC4Ba2a08E58C7ECc3DE48e3C825262caF8")

transaction := types.DynamicFeeTx{
  ChainID:   big.NewInt(84532),
  Nonce:     0,
  To:        &toAddress,
  Value:     big.NewInt(10000000000000), // 0.00001 ETH
  Data:      []byte{},
  Gas:       21000,
  GasFeeCap: big.NewInt(1000000000), // 1 gwei max fee
  GasTipCap: big.NewInt(100000000),  // 0.1 gwei max priority fee
}

// Serialize transaction to RLP
rlpTx := types.NewTx(&transaction)
rlpData, err := rlpTx.MarshalBinary()
if err != nil {
  return "", err
}

rlpHex := hex.EncodeToString(rlpData)
rlpHex = "0x" + rlpHex

response, err := cdp.SignEvmTransactionWithResponse(
  ctx,
  evmAddress,
  nil,
  openapi.SignEvmTransactionJSONRequestBody{
    Transaction: rlpHex,
  },
)
if err != nil {
  return "", err
}

if response.StatusCode() != 200 {
  return "", fmt.Errorf("failed to sign transaction: %v", response.Status())
}

Authentication tools

This SDK also contains simple tools for authenticating REST API requests to the Coinbase Developer Platform (CDP) in the auth/ directory.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For feature requests, feedback, or questions, please reach out to us in the #cdp-sdk channel of the Coinbase Developer Platform Discord.

Security

If you discover a security vulnerability within this SDK, please see our Security Policy for disclosure information.