NEW

CCIP is now live for all developers. See what's new.

Back

Dev3 Chainlink SDK

Learn how to install and use the Dev3 Chainlink SDK in your applications.

Overview

The Dev3 Chainlink SDK module is a fully open source TypeScript SDK which enables any frontend developer to fetch the prices of various assets through Chainlink Data Feeds. The SDK works with vanilla npm projects and frontend frameworks like Angular and React. Users can fetch price pairs, NFT floor price information, and more.

Objective

You will install and use the Dev3 SDK to monitor a Chainlink price feed. Optionally, you can also deploy a Dev3 Chainlink SDK template from the Dev3 dashboard.

Before you begin

Before you start this tutorial, complete the following items:

  • Install git
    • Run git --version to check the installation. You should see an output similar to git version x.x.x.
  • Install Nodejs 16.0.0 or higher
    • Run node --version to check the installation. You should see an output similar to v16.x.x.

Install and initialize the SDK

Install the Dev3 SDK in your npm project.

  1. Type the following command on your terminal while on your project's root folder:

    npm install dev3-sdk
    
  2. In your JavaScript or TypeScript file:

    1. Import the Chainlink module:

      import { Chainlink } from "dev3-sdk"
      
    2. Get an RPC URL for the network where you want to monitor price feeds. For example, a public node for Ethereum is https://ethereum.publicnode.com.

    3. Fill in your RPC URL and then initialize the SDK by calling:

      const ethSDK = Chainlink.instance("https://ethereum.publicnode.com", Chainlink.PriceFeeds.ETH)
      

      This sets up reading data feeds for Ethereum mainnet.

Consuming data feeds

Once the SDK is initialized, you can start consuming different feeds as outlined in the examples below:

  1. Add the following code to your JavaScript or TypeScript file:
    // AAVE/ETH price feed
    ethSDK.getFromOracle(ethSDK.feeds.AAVE_ETH).then((res) => {
        console.log(res.answer.toString());
    });
    
  2. Run your file. For example:
    node index.js
    
  3. The output should be similar to: 40104190000000000. Compare this to the AAVE / ETH price feed, which returns Ξ0.04010419 at the time of writing.

Full list of feeds

You can find all available feeds by visiting data.chain.link.

Reading data

The data is returned in the form of a RoundDataModel object:

export interface RoundDataModel {
  roundID: BigNumber
  answer: BigNumber
  formattedAnswer?: string
  startedAt: BigNumber
  updatedAt: BigNumber
  answeredInRound: BigNumber
  assetName?: string
  dataFeedName?: string
}

Deployable templates

The Dev3 SDK includes Chainlink interfaces and contracts that you can deploy from the Dev3 dashboard. You can use these interfaces and contracts from within your frontends and/or wallets.

To deploy them, navigate to the Dev3 dashboard and choose the Deploy from template option in your workspace. Search for "chainlink" within your Dev3 workspace, or view the source code directly:

Additional information

  • The source code for this extension is extracted to the GitHub repo so you can also use it as a standalone module.
  • Dev3 Chainlink SDK extracts all the pair contracts addresses for all networks that are compatible into code generated classes, so all modern editors will support full code autocomplete.

Contract address pairs screenshot

Stay updated on the latest Chainlink news