Mint Provider

📘 Mint info Provider

API

<MintProvider> ... </MintProvider>

For example

import { MintProvider } from '@sentre/senhub'

// Wrap a paragraph as a child.
<MintProvider>
  <p>Hello world</p>
</MintProvider>

Context

type Provider {
  mints: State
  getMint: (mintAddress: string) => Promise<MintData>
  getDecimals: (mintAddress: string) => Promise<number>
  tokenProvider: TokenProvider
}

type State = Record<string, MintData>
type MintData = {
  mint_authority_option: number;
  mint_authority: string;
  supply: bigint;
  decimals: number;
  is_initialized: boolean;
  freeze_authority_option: number;
  freeze_authority: number;
}
type TokenProvider = any // See the table below

Provider

MintData

Hook & HOC

import { useMint, withMint } from '@senhub/providers'

For example

Wrap the parent by MintProvider before accessing the context.

import { useMint, withMint } from '@senhub/providers'

// Within a functional component
const Component = () => {
  const { mints } = useMint()
  console.log(mints['5YwUkPdXLoujGkZuo9B4LsLKj3hdkDcfP4derpspifSJ'])
  // mint_authority_option: 1
  // mint_authority: "5vHjWRc2hys4XwZkMktg35N8oALt5d1ZXYkwCXXX3JHm"
  // supply: 5000000000000000000n
  // decimals: 9
  // is_initialized: true
  // freeze_authority_option: 0
  // freeze_authority: "11111111111111111111111111111111"
}
export default Component

// Within a class component
class Component {
  render() {
    const { mints } = this.props
    console.log(mints['5YwUkPdXLoujGkZuo9B4LsLKj3hdkDcfP4derpspifSJ'])
    // mint_authority_option: 1
    // mint_authority: "5vHjWRc2hys4XwZkMktg35N8oALt5d1ZXYkwCXXX3JHm"
    // supply: 5000000000000000000n
    // decimals: 9
    // is_initialized: true
    // freeze_authority_option: 0
    // freeze_authority: "11111111111111111111111111111111"
  }
}
export default withMint(Component)

TokenProvider

In this document, we will use token and mint interchangeably. However, the meaning of both is the same.

Actually, tokenProvider is an instance from TokenProvider class. By the instance, you can find token metadata by its symbol or name for example. That way is more intuitive than using mint addresses.

TokenProvider API

You can learn more data types in the original repo: https://github.com/solana-labs/token-list.

TokenInfo

interface TokenInfo {
  readonly chainId: number;
  readonly address: string;
  readonly name: string;
  readonly decimals: number;
  readonly symbol: string;
  readonly logoURI?: string;
  readonly tags?: string[];
  readonly extensions?: TokenExtensions;
}

Example: all

const { tokenProvier } = useMint()

const allTokenList = await tokenProvider.all()
console.log(allTokenList)
// [
//    ...,
//    {
//        address: "So11111111111111111111111111111111111111112"
//        chainId: 103
//        decimals: 9
//        extensions: {coingeckoId: "solana"}
//        logoURI: "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png"
//        name: "Wrapped SOL"
//        symbol: "SOL"
//        tags: []
//    },
//    ...
// ]

Example: findByAddress

const { tokenProvier } = useMint()

const wsol = await tokenProvider.findByAddress("So11111111111111111111111111111111111111112")
console.log(wsol)
// {
//    address: "So11111111111111111111111111111111111111112"
//    chainId: 103
//    decimals: 9
//    extensions: {coingeckoId: "solana"}
//    logoURI: "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png"
//    name: "Wrapped SOL"
//    symbol: "SOL"
//    tags: []
// }

Example: find

const { tokenProvier } = useMint()

const solRelatedTokenList = await tokenProvider.find("sol")
console.log(solRelatedTokenList)
// [
//    {
//        address: "So11111111111111111111111111111111111111112"
//        chainId: 103
//        decimals: 9
//        extensions: {coingeckoId: "solana"}
//        logoURI: "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png"
//        name: "Wrapped SOL"
//        symbol: "SOL"
//        tags: []
//    },
//    {
//        address: "2rg5syU3DSwwWs778FQ6yczDKhS14NM3vP4hqnkJ2jsM"
//        chainId: 103
//        decimals: 9
//        extensions: {
//            background: "https://solana.com/static/8c151e179d2d7e80255bdae6563209f2/6833b/validators.webp"
//            website: "https://solana.com/"
//        }
//        logoURI: "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/2rg5syU3DSwwWs778FQ6yczDKhS14NM3vP4hqnkJ2jsM/logo.png"
//        name: "SOL stake pool"
//        symbol: "pSOL"
//        tags: []
//    },
// ]

Last updated