@prgm/token-offchain-metadata@0.3.3Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
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.
Add Package
deno add jsr:@prgm/token-offchain-metadata
Import symbol
import * as token_offchain_metadata from "@prgm/token-offchain-metadata";
Import directly with a jsr specifier
import * as token_offchain_metadata from "jsr:@prgm/token-offchain-metadata";