@tonic-foundation/token-list
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

token-list

This is a fork of the popular @solana-labs/token-list for NEAR/Aurora.

Contents

Usage

@tonic-foundation/token-list

npm GitHub license

@tonic-foundation/token-list is a package that allows application to query for list of tokens. The JSON schema for the tokens includes: chainId, address, name, decimals, symbol, logoURI (optional), tags (optional), and custom extensions metadata.

The interface is nearly identical to @solana-labs/token-list for ease of use.

Installation

npm install @tonic-foundation/token-list
yarn add @tonic-foundation/token-list

Examples

Query available tokens

new TokenListProvider().resolve().then((tokens) => {
  const tokenList = tokens.filterByNearEnv('mainnet').getList();
  console.log(tokenList);
});

Render icon for token in React

import React, { useEffect, useState } from 'react';
import { TokenListProvider, TokenInfo } from '@tonic-foundation/token-list';


export const Icon = (props: { mint: string }) => {
  const [tokenMap, setTokenMap] = useState<Map<string, TokenInfo>>(new Map());

  useEffect(() => {
    new TokenListProvider().resolve().then(tokens => {
      const tokenList = tokens.filterByNearEnv('mainnet').getList();

      setTokenMap(tokenList.reduce((map, item) => {
        map.set(item.address, item);
        return map;
      },new Map()));
    });
  }, [setTokenMap]);

  const token = tokenMap.get(props.mint);
  if (!token || !token.logoURI) return null;

  return (<img src={token.logoURI} />);

Readme

Keywords

none

Package Sidebar

Install

npm i @tonic-foundation/token-list

Weekly Downloads

72

Version

0.0.8

License

none

Unpacked Size

118 kB

Total Files

13

Last publish

Collaborators

  • markobosnic
  • renthog