API Reference
DocumentationLog In

The Coinbase Cloud SDK is a JavaScript SDK that provides access to Coinbase Cloud's Node APIs.

With the SDK, you can:

Supported networks

The SDK supports the following blockchain networks:

  • Ethereum: Mainnet, Goerli

Prerequisites

A Coinbase Node project is required to use the SDK.

To register and create a project, get started here.

Install

The Coinbase Cloud SDK is available on npm.

To install with yarn:

yarn add @coinbase/coinbase-cloud-sdk

To install with npm:

npm install @coinbase/coinbase-cloud-sdk

Usage

Once the SDK has been installed, you can import and use it within your project.

Setup

To initialize the SDK, create an instance of CoinbaseCloud and pass it the authentication credentials found within your project's settings.

import { CoinbaseCloud, Network } from 'coinbase-cloud-sdk';

const settings = {
 apiUsername: 'YOUR_USERNAME', // You can find this in your Node project's settings
 apiPassword: 'YOUR_PASSWORD', // Password associated with the username
 network: Network.ETH_MAINNET
};

const coinbaseCloud = new CoinbaseCloud(settings);

const blockNumber = await coinbaseCloud.provider.getBlockNumber();
const balance = await coinbaseCloud.provider
 .getBalance('0xf977814e90da44bfa03b6295a0616a897441acec');

Making requests

The SDK provides the following namespaces for making requests:

Coinbase Cloud Provider

Below is an example of how to make a request using the CoinbaseCloudProvider to get the ETH balance of an address:

// Request to get the ETH balance of an address
const balance = await coinbaseCloud.provider
 .getBalance('0xf977814e90da44bfa03b6295a0616a897441acec');

๐Ÿ“˜

Note: The Coinbase Cloud provider can be extracted and used as any other ethers.js JsonRpcProvider.

For more details about the Coinbase Cloud provider, see the API reference.

Advanced API

Below is an example of how to make an Advanced API request to get multiple token balances for a single address:

// Advanced API request to get multiple ERC-20 token balances of an address
const balances = await coinbaseCloud.advanced
 .getBalances([
   {
     address: '0xdf0635793e91d4f8e7426dbd9ed08471186f428d',
     contract: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
   },
   {
     address: '0xdf0635793e91d4f8e7426dbd9ed08471186f428d',
     contract: '0x6b175474e89094c44da98b954eedeac495271d0f'
   }
 ]);

For a list of available Advanced API methods, see the API Reference.

API Reference

API reference documentation for the Coinbase Cloud SDK is generated and made available in the GitHub repository.