This quickstart shows you how to invoke the Onchain Reputation API using CDP SDK, retrieving reputation and risk details associated with an address. Reputation scores can only be returned for Base and Ethereum. Risk scores can be returned for Base, Bitcoin, or Ethereum.

Requirements

Make sure your developer environment satisfies all of the requirements before proceeding through the quickstart.

Node.js 18+

The Coinbase server-side SDK requires Node.js version 18 or higher and npm version 9.7.2 or higher. To view your currently installed versions of Node.js, run the following from the command-line:

node -v
npm -v

We recommend installing and managing Node.js and npm versions with nvm. See Installing and Updating in the nvm README for instructions on how to install nvm.

Once nvm has been installed, you can install and use the latest versions of Node.js and npm by running the following commands:

nvm install node # "node" is an alias for the latest version
nvm use node

Installation

Clone CDP SDK quickstart template The CDP SDK provides a quickstart template to get started with the SDK. Clone the repository and navigate to the quickstart template directory:

git clone git@github.com:coinbase/coinbase-sdk-nodejs.git; cd coinbase-sdk-nodejs/quickstart-template

Install the dependencies:

npm install

The file index.js contains the code to perform your first transfer with the CDP SDK. Let’s break down the content of this file.

Configure your CDP API Key as outlined here.

Using the Onchain Reputation API

The code snippet below demonstrates invoking the Onchain Reputation API:

// Define the external address or ENS
let externalAddress = new ExternalAddress("YOUR_NETWORK", "YOUR_WALLET_ADDRESS"); 

// Fetch reputation metadata for the address as JSON including score, reputation metadata, and risk metadata
const addressReputation = await externalAddress.reputation();

// addressReputation.risky returns 0 if no risk indicated, or 1 if risk indicated
if(addressReputation.risky) {
    // actions if risk indicated
}

// addressReputation.metadata returns a JSON summarizing the address's transaction history

// addressReputation.score returns the numerical score between -100 and +100
if(addressReputation.score > 50) {
    // actions based on reputation score
}