Skip to content

Latest commit

 

History

History
59 lines (40 loc) · 1.71 KB

README.md

File metadata and controls

59 lines (40 loc) · 1.71 KB

@solana/spl-token-registry

npm GitHub license

Solana Token Registry is a package that allows application to query for list of tokens. JSON schema for the tokens includes: chainId, address, name, decimals, symbol, logoURI (optional), tags (optional), and custom extensions metadata.

Installation

npm install @solana/spl-token-registry
yarn install @solana/spl-token-registry

Examples

Query available tokens

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

Render icon for token in React

import React, { useEffect, useState } from 'react';
import { TokenListProvider, KnownToken } from '@solana/spl-token-registry';


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

  useEffect(() => {
    new TokenListProvider().resolve().then(tokens => {
      const tokenList = tokens.filterByChain(ENV.MainnetBeta).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} />);

Adding new token

Submit PR with changes to JSON file src/tokens/solana.tokenlist.json