tokenprices
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

tokenprices

A simple and easy library to fetch token prices on-chain.

Powered by Ethers.js.

npm install tokenprices

Usage

Using tokenprices is quite simple:

<TokenPrices>.fetchPrice(<TOKEN ADDRESS> || <TokenPrices>.tokenlist.<TOKEN NAME>)

Example

Here is an example of tokenprices in action:

import { TokenPrices } from 'tokenprices';
import { JsonRpcProvider } from '@ethersproject/providers';

const provider = new JsonRpcProvider(<RPC URL HERE>);

const getPrices = async () => {
    const tokenprices = new TokenPrices();
    await tokenprices.init(provider);

    const wmaticPrice = await tokenprices.fetchPrice(tokenprices.tokenlist.WMATIC);
    const belugaPrice = await tokenprices.fetchPrice(tokenprices.tokenlist.BELUGA);

    console.log("WMATIC price:", wmaticPrice / 1e18);
    console.log("BELUGA price:", belugaPrice / 1e18);
}

getPrices();

Supported Networks

Tokenprices supports the following networks and price sources:

  • Polygon Mainnet (Chainlink, Gravity, Sushiswap, Quickswap, and Apeswap)
  • Fantom Opera (Chainlink, Spookyswap, Sushiswap, and Spiritswap)

Support

If you encounter any issues whilst using this library, you can join our Discord server to ask for help.

Dependents (0)

Package Sidebar

Install

npm i tokenprices

Weekly Downloads

3

Version

1.0.4

License

Unlicense

Unpacked Size

26 kB

Total Files

15

Last publish

Collaborators

  • chainvisions