Comment on page
Mint Provider
📘 Mint info Provider
<MintProvider> ... </MintProvider>
Property | Type | Description | Default |
---|---|---|---|
children | ReactNode | The wrapped children. | undefined |
import { MintProvider } from '@sentre/senhub'
// Wrap a paragraph as a child.
<MintProvider>
<p>Hello world</p>
</MintProvider>
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
Property | Type | Description |
---|---|---|
mints | Record<string, MintData> | A mapping from a mint address to the corresponding mint data. |
getMint | async (mintAddress: string): Promise<MintData> | Fetch mint data from live nodes or local cache by a mint address. |
getDecimals | async (mintAddress: string): Promise<number> | Find decimals for the mint. |
tokenProvider | TokenProvider | The mint metadata provider (i.e. logo uri, coingecko or coinmarketcap ticket). See the TokenProvider section for details. |
Property | Type | Description |
---|---|---|
mint_authority_option | 0 | 1 | Whether the mint_authority property is available. |
mint_authority | string | The authority address that can mint more token. |
supply | bigint | Total supply. |
decimals | number | Decimals. |
is_initialized | boolean | Whether the mint is initialized. |
freeze_authority_option | bigint | Whether the freeze_authority property is available. |
freeze_authority | string | The authority address that can freeze accounts corresponding to the mint. |
import { useMint, withMint } from '@senhub/providers'
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)
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.
Property | Type | Description |
---|---|---|
find | async (keyword: string, limit?: 10): Promise<TokenInfo[]> | Semantic search tokens. The function can search mutiple tokens. |
findByAddress | async (addr: string): Promise<TokenInfo | undefined> | Find a token by its address. |
all | async (): Promise<TokenInfo[]> | Get all tokens. |
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;
}
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: []
// },
// ...
// ]
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: []
// }
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 modified 1yr ago