close
Skip to main content

Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, BrowsersIt is unknown whether this package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score100%
Downloads1/wk
Publisheda year ago (0.3.3)

A library to retrieve extra token metadata like logo images using a chain ID and an address

Token Offchain Metadata

This library provides a way to retrieve a token image from a token address.

It relies on the parsing of token lists to retrieve the metadata of tokens.

Usage

Loading token metadata from a token list

Instantiate a TokenMetadataStore, and then call fetchTokensFromList with the URL of a token list to fetch and parse the token metadata:

import { TokenMetadataStore, toHttpsUrl } from "@prgm/token-offchain-metadata";

const metadataStore = new TokenMetadataStore();
await metadataStore.fetchTokensFromList(toHttpsUrl("ipns://tokens.uniswap.org"));

Retrieving token metadata

You can retrieve the metadata of a token that was added by calling getTokenFromAddress with the chain ID and address of the token:

const metadata = metadataStore.getTokenFromAddress({
  chainId: 1,
  address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
});

This will return a TokenMetadata object that will contain some chain-agnostic metadata for the token.

Manually adding token image sources

If you have image sources for a token that are not included in the token list, you can add them manually by calling addTokenLogoImageSources.

For example, if you have custom image for the DAI token, add a token image source for DAI:

metadataStore.addTokenLogoImageSources(
  { chainId: 1, address: "0x6B175474E89094C44Da98b954EedeAC495271d0F" },
  "/static/images/dai.png",
);

Note that if it was "bridged" by one of the token lists, it will be added to the metadata of all associated tokens across chains.

Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@prgm/token-offchain-metadata

Import symbol

import * as token_offchain_metadata from "@prgm/token-offchain-metadata";
or

Import directly with a jsr specifier

import * as token_offchain_metadata from "jsr:@prgm/token-offchain-metadata";