npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@coinbase/coinbase-cloud-sdk

v0.0.1

Published

Coinbase Cloud JavaScript SDK

Downloads

11

Readme

Coinbase Cloud SDK

npm

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

With the SDK, you can:

  • Make requests to native Ethereum APIs, using an ethers.js compatible Provider.
  • Make requests to Coinbase Node's Advanced APIs, providing access to aggregated and filtered blockchain data in a single query.

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:

  • provider: Contains methods for making calls to native Ethereum APIs, using an ethers.js compatible Provider.
  • advanced: Contains methods for making calls to Coinbase Node's Advanced APIs.

Ethereum API

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

Advanced API

// 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'
    }
  ]);

Examples

Below are a few examples for making requests to Coinbase Node's Advanced APIs using the SDK.

For more examples, please visit the Coinbase Node developer documentation.

Advanced Data APIs

Balances

GetSingleBalance
import { GetSingleBalanceResponse } from 'coinbase-cloud-sdk';

const singleBalance: GetSingleBalanceResponse = await coinbaseCloud.advanced
  .getSingleBalance(
    '0x00000000DF0635793e91d4f8e7426dbd9ed08471186f428D',
    '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
  );
GetBalances
import { GetBalancesResponse } from 'coinbase-cloud-sdk';

const balances: GetBalancesResponse = await coinbaseCloud.advanced
  .getBalances([
    {
      address: '0x00000000DF0635793e91d4f8e7426dbd9ed08471186f428D',
      contract: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
    },
    {
      address: '0xdf0635793e91d4f8e7426dbd9ed08471186f428d',
      contract: '0x6b175474e89094c44da98b954eedeac495271d0f'
    }
  ]);

Allowances

GetTokenAllowances
import { GetTokenAllowancesResponse } from 'coinbase-cloud-sdk';

const allowances: GetTokenAllowancesResponse = await coinbaseCloud.advanced
  .getTokenAllowances([
    {
      owner: '0xa646147bda82a866eba03568f363fc9c90185c6e',
      spender: '0xadd0e097b961572b2a1f5de572c622eef97e3d82',
      contracts: ['0xdac17f958d2ee523a2206206994597c13d831ec7']
    }
  ]);

Transactions & Transfers

GetTransactionByHash
import { GetTransactionByHashResponse } from 'coinbase-cloud-sdk';

const transaction: GetTransactionByHashResponse = await coinbaseCloud.advanced
  .getTransactionByHash(
    '0x2be70b2bcff662ba941c3f3c7706ef2c674d0d0ea4a13a91543cbe18862063d4'
  );
GetTransactionsByAddress
import { GetTransactionsByAddressResponse } from 'coinbase-cloud-sdk';

const transactions: GetTransactionsByAddressResponse = await coinbaseCloud.advanced
  .getTransactionsByAddress(
    '0xcAfB10eE663f465f9d10588AC44eD20eD608C11e',
    '0x0',
    '0xf183f2',
    'SENDER_OR_RECEIVER',
    'desc',
    20,
    1
  );
GetTokenTransfersByAddress
import { GetTokenTransfersByAddressResponse } from 'coinbase-cloud-sdk';

const tokenTransfers: GetTokenTransfersByAddressResponse = await coinbaseCloud.advanced
  .getTokenTransfersByAddress(
    '0x0000000000000000000000000000000000000000',
    '0xdb0db3',
    '0xea11e0',
    'RECEIVER_ONLY',
    'asc',
    10,
    1
  );

Contracts

GetTokenStandardEvents
import { GetTokenStandardEventsResponse } from 'coinbase-cloud-sdk';

const tokenEvents: GetTokenStandardEventsResponse = await coinbaseCloud.advanced
  .getTokenStandardEvents(
    '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    '0x1',
    '0xea11e0',
    ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'],
    'desc',
    10,
    1
  );
GetTokenMetadata
import { GetTokenContractMetadataResponse } from 'coinbase-cloud-sdk';

const tokenMetadata: GetTokenContractMetadataResponse = await coinbaseCloud.advanced
  .getTokenMetadata('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48');

References

Contributing

Commit signing is required for contributing to this repo. For details, see the docs on contributing and commit-signing.

License

See LICENSE.