Giter VIP home page Giter VIP logo

utl-sdk's Introduction

Solflare

@solflare-wallet/utl-sdk

SDK used for Unified Token List.

This SDK works by fetching token metadata using a few different strategies: using UTL backend, falling back to token list hosted on publicly available CDN, and fetching Metaplex metadata for everything else.

Contents:

Inspiration for this token list

As the current token list is coming to its end and being archived, the need for new token list was created. Previous token list was based on GitHub repo and anybody could create a PR and introduce their mint/token into that list that was used by whole community. Since PRs were loosely monitored and in huge numbers, that meant that scam tokens could be found inside the list.

Our proposition is creating an open-source transparent Unified Token List (UTL) that combines credible and trusted sources of verified token mints across the community.

Everyone will be able to independently generate the UTL, customize the list and use it or just use a pre-generated one.

Main parts of UTL are:

Installation

$ npm install @solflare-wallet/utl-sdk

Examples

Initialize the library

  1. Use the default configuration (it will create a new Solana web3 connection with public mainnet-beta rpc):
import { Client } from '@solflare-wallet/utl-sdk';

const utl = new Client();
  1. Extend your configuration with other options:
import { Client, UtlConfig } from '@solflare-wallet/utl-sdk';

const config = new UtlConfig({
  /**
   * 101 - mainnet, 102 - testnet, 103 - devnet
   */
  chainId: 101,
  /**
   * number of miliseconds to wait until falling back to CDN
   */
  timeout: 2000,
  /**
   * Solana web3 Connection
   */
  connection: new Connection('https://api.mainnet-beta.solana.com/'),
  /**
   * Backend API url which is used to query tokens
   */
  apiUrl: "https://token-list-api.solana.cloud",
  /**
   * CDN hosted static token list json which is used in case backend is down
   */
  cdnUrl: "https://cdn.jsdelivr.net/gh/solflare-wallet/token-list/solana-tokenlist.json"
});

const utl = new Client(config);

Fetching a single token

import { Client, Token } from '@solflare-wallet/utl-sdk';
import { PublicKey } from '@solana/web3.js';

const utl = new Client();
const token: Token = await utl.fetchMint(new PublicKey("So11111111111111111111111111111111111111112"));

token = {
  address: 'So11111111111111111111111111111111111111112',
  chainId: 101,
  name: 'Wrapped Solana',
  symbol: 'SOL',
  verified: true,
  decimals: 9,
  holders: 100000,
  logoURI: 'https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png',
  tags: []
}

Fetching multiple tokens

import { Client, Token } from '@solflare-wallet/utl-sdk';
import { PublicKey } from '@solana/web3.js';

const mints = [
  new PublicKey("So11111111111111111111111111111111111111112"), // WSOL
  new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"), // USDC
  new PublicKey("FjWWxNDB2uVjeaKR7nVjFjxTau85wVfAzwbLbpmJot3v") // Fake USDC (fetched from Metaplex metadata)
];

const utl = new Client();
const tokens: Token[] = await utl.fetchMints(mints);

Searching tokens

import { Client, Token } from '@solflare-wallet/utl-sdk';
import { PublicKey } from '@solana/web3.js';

const utl = new Client();
const options = { start: 0, limit: 10 };
const tokens = await utl.searchMints('slrs', options);

tokens = {
  data: [ Token, Token ],
  start: 0,
  limit: 10,
  count: 1234
}

utl-sdk's People

Contributors

turshija avatar vsakos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.