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

chainstack-covalent-sdk

v1.0.8

Published

An SDK designed to streamline the process of developing using the integration of Chainstack with Covalent APIs, enhancing the ease of use and efficiency

Downloads

20

Readme

Chainstack Covalent API JavaScript SDK

A JavaScript SDK designed to streamline the process of developing using the integration of Chainstack with Covalent APIs, enhancing the ease of use and efficiency.

Quickstart

npm i chainstack-covalent-sdk
  • In a new file, import the Chainstack SDK and use your Chainstack API key in the constructor:
const {ChainstackApi} = require("chainstack-covalent-sdk")

const CHAINSTACK_API_KEY = 'YOUR_CHAINSTACK_API_KEY'
const chainstack = new ChainstackApi(CHAINSTACK_API_KEY);
  • (Optional but recommended) — The Chainstack-Covalent SDK comes with the dotenv package included, so you can use a .env file to import the Chainstack API key:

    • Create a .env file with your Chainstack API key:
    CHAINSTACK_API_KEY="YOUR_CHAINSTACK_API_KEY"
    • Import it in your project:
    const {ChainstackApi} = require("chainstack-covalent-sdk")
    
    const CHAINSTACK_API_KEY = process.env.CHAINSTACK_API_KEY
    const chainstack = new ChainstackApi(CHAINSTACK_API_KEY);

Usage

The Chainstack-Covalent SDK has many endpoints to get all sorts of data, from smart contract deployments to NFT data. Each endpoint takes an object as a parameter to configure the call to the Covalent API.

Fetch token balances

This endpoint fetches all the token balances from the specified address on the selected chain:

const {ChainstackApi} = require("chainstack-covalent-sdk")

const CHAINSTACK_API_KEY = process.env.CHAINSTACK_API_KEY
const chainstack = new ChainstackApi(CHAINSTACK_API_KEY);

// Config parameters
const parameters = {
    chainName: 'eth-mainnet',
    walletAddress: '0xae2Fc483527B8EF99EB5D9B44875F005ba1FaE13',
    currency: 'USD',
    nft: true,
    noNftFetch: false,
    noSpam: true,
  };
  
  
  chainstack.fetchTokenBalances(parameters)
    .then(data => console.log(data))
    .catch(error => console.error(error));

Explain the parameter object

The parameters object allows for fine tuning of your request, here is the explanation about the configuration parameters for fetchTokenBalances:

  1. chainName (string, required): This parameter represents the name of the blockchain network you're interested in. For example, 'eth-mainnet' for the Ethereum mainnet. Find a complete list on the Covalent docs.

    const chainName = 'eth-mainnet';
  2. walletAddress (string, required): This is the address of the wallet for which you want to fetch token balances. If you pass in an Ethereum Name Service (ENS) address or a RSK Name Service (RNS) address, it will be automatically resolved to the corresponding wallet address.

    const walletAddress = '0xae2Fc483527B8EF99EB5D9B44875F005ba1FaE13';
  3. quote-currency (string, optional): This is the currency in which you want the balances to be quoted, such as 'USD' for United States Dollars. If not provided, the balances may be returned in the native currency of the blockchain network.

    const quoteCurrency = 'USD';
  4. nft (boolean, optional): If set to true, Non-Fungible Tokens (NFTs) will be included in the response along with fungible tokens. If false or not provided, NFTs will not be included.

    const nft = true;
  5. no-nft-fetch (boolean, optional): If set to true, the response will only include NFTs that have been cached. This can make the response faster, as it avoids having to fetch data about NFTs from the blockchain. If false or not provided, all NFTs will be included, regardless of whether they are cached.

    const noNftFetch = false;
  6. no-spam (boolean, optional): If set to true, any tokens that are suspected to be spam will be excluded from the response. This currently supports 'eth-mainnet' and 'matic-mainnet'. If false or not provided, all tokens, including potential spam, will be included.

    const noSpam = true;

Remember, this function returns a promise. Handle this promise appropriately in your code, either by using .then() and .catch() methods, or by using the await keyword inside an async function with a try-catch block.

Work in progress

This tool and its documentation is work in progress, we will be adding a complete list of endpoints available soon.