Coinbase JavaScript SDK example: cbapp-public-rest-all.ts

Coinbase cbapp public REST all JavaScript example for the Siebly Coinbase SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.

We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.

examples/Coinbase/CoinbaseApp/Public/cbapp-public-rest-all.ts

What this example covers

  • Coinbase exchange API JavaScript example.
  • Uses the Siebly Coinbase SDK package coinbase-api instead of hand-written HTTP request plumbing.
  • Source path: Coinbase/CoinbaseApp/Public/cbapp-public-rest-all.ts.
  • Imports SDK symbols including CBAppClient.
  • Calls SDK methods such as getFiatCurrencies(), getCryptocurrencies(), getExchangeRates(), getBuyPrice(), getSellPrice(), getSpotPrice(), getCurrentTime().

How to use this example

  • Start here for the specific request or stream pattern, then check the matching SDK guide for install, credentials, and operational notes.
  • Open the repository source when you need the latest committed version: GitHub source file.
import { CBAppClient } from 'coinbase-api'; // Initialize the client, you can pass in api keys here if you have them but they are not required for public endpointsconst client = new CBAppClient(); async function publicCalls() {  try {    // Get fiat currencies    const fiatCurrencies = await client.getFiatCurrencies();    console.log('Fiat Currencies: ', fiatCurrencies);     // Get cryptocurrencies    const cryptocurrencies = await client.getCryptocurrencies();    console.log('Cryptocurrencies: ', cryptocurrencies);     // Get exchange rates    const exchangeRates = await client.getExchangeRates({ currency: 'USD' });    console.log('Exchange Rates: ', exchangeRates);     // Get buy price    const buyPrice = await client.getBuyPrice({ currencyPair: 'BTC-USD' });    console.log('Buy Price: ', buyPrice);     // Get sell price    const sellPrice = await client.getSellPrice({ currencyPair: 'BTC-USD' });    console.log('Sell Price: ', sellPrice);     // Get spot price    const spotPrice = await client.getSpotPrice({ currencyPair: 'BTC-USD' });    console.log('Spot Price: ', spotPrice);     // Get current time    const currentTime = await client.getCurrentTime();    console.log('Current Time: ', currentTime);  } catch (e) {    console.error('Error: ', e);  }} publicCalls(); 

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.