Code Monkey home page Code Monkey logo

ankrjs's Introduction

⚓️ ankr.js

Compact JavaScript library for interacting with Ankr's Advanced APIs.

Get started in 2 minutes

1. Install the package from npm

# with npm
npm install @ankr.com/ankr.js

# with yarn
yarn add @ankr.com/ankr.js

2. Initialize the provider

Note: to use Advanced API for free starting from 29.05.2023 you have to register on the platform.

Get your individual endpoint here https://www.ankr.com/rpc/advanced-api and provide it to the AnkrProvider constructor.

import { AnkrProvider } from '@ankr.com/ankr.js';

const provider = new AnkrProvider('YOUR_ENDPOINT');

3. Use the provider and call one of the supported methods

await provider.getNFTsByOwner({
  blockchain: 'eth',
  walletAddress: '0x0E11A192d574b342C51be9e306694C41547185DD',
});

Supported chains

ankr.js supports the following chains at this time:

  • Ethereum: "eth"

  • BNB Smart Chain: "bsc"

  • Polygon: "polygon"

  • Fantom: "fantom"

  • Arbitrum: "arbitrum"

  • Avalanche: "avalanche"

  • Syscoin NEVM: "syscoin"

  • Optimism: "optimism"

  • Ethereum Goerli: "eth_goerli"

  • Avalanche Fuji: "avalanche_fuji"

Available methods

ankr.js supports the following methods:

getLogs

Get logs matching the filter.

const logs = async () => {
  return await provider.getLogs({
    blockchain: 'eth',
    fromBlock: 1181739,
    toBlock: 1181739,
    topics: [
      [],
      ['0x000000000000000000000000feb92d30bf01ff9a1901666c5573532bfa07eeec'],
    ],
    address: '0x3589d05a1ec4af9f65b0e5554e645707775ee43c',
    decodeLogs: false,
  });
};

getBlocks

Query data about blocks within a specified range.

const blocks = async () => {
  return await provider.getBlocks({
    blockchain: 'bsc',
    fromBlock: 100,
    toBlock: 200,
  });
};

getTransactionsByHash

Query data about transaction(s) by the transaction hash.

const transactions = async () => {
  return await provider.getTransactionsByHash({
    transactionHash:
      '0x82c13aaac6f0b6471afb94a3a64ae89d45baa3608ad397621dbb0d847f51196f',
    decodeTxData: true,
  });
};

getAccountBalance

Get the coin and token balances of a wallet.

const balances = async () => {
  return await provider.getAccountBalance({
    blockchain: 'eth',
    walletAddress: '0xfa9019df60d3c710d7d583b2d69e18d412257617',
  });
};

getNFTsByOwner

Get data about all the NFTs (collectibles) owned by a wallet.

const nfts = async () => {
  return await provider.getNFTsByOwner({
    blockchain: 'eth',
    walletAddress: '0x0E11A192d574b342C51be9e306694C41547185DD',
    filter: [
      { '0x700b4b9f39bb1faf5d0d16a20488f2733550bff4': [] },
      { '0xd8682bfa6918b0174f287b888e765b9a1b4dc9c3': ['8937'] },
    ],
  });
};

getTokenHolders

Get the list of token holders for a given contract address.

const tokenHolders = async () => {
  return await provider.getTokenHolders({
    blockchain: 'eth',
    contractAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
  });
};

getTokenHoldersCount

Get current and historical data about the number of token holders for a given contract address.

const tokenHoldersCount = async () => {
  return await provider.getTokenHoldersCount({
    blockchain: 'eth',
    contractAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
  });
};

getCurrencies

Get a list of supported currencies for a given blockchain.

const currencies = async () => {
  return await provider.getCurrencies({ blockchain: 'fantom' });
};

About API keys

Ankr is offering free access to Advanced API, however you have to register on Ankr platform to access it. Get your individual endpoint here https://www.ankr.com/rpc/advanced-api.

ankrjs's People

Stargazers

 avatar Nicolas Ortiz avatar David avatar

Watchers

999bits avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.