Skip to content

highacrypto/token-list

Repository files navigation

@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: name, symbol, logo and mint account address

Installation

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

Examples

Query available tokens

new TokenListProvider().resolve("mainnet-beta").then(tokens => {
  console.log(tokens);
});

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("mainnet-beta").then(tokens => {
      setTokenMap(tokens.reduce((map, item) => {
        map.set(item.mintAddress, item);
        return map;
      },new Map()));
    });
  }, [setTokenMap]);

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

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

Adding new token

Submit PR with changes to JSON file src/tokens/<env>.json

About

The community maintained Solana token registry

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%