Copy < MintProvider > ... </ MintProvider >
Copy import { MintProvider } from '@sentre/senhub'
// Wrap a paragraph as a child.
< MintProvider >
< p >Hello world</ p >
</ MintProvider >
Copy 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
Copy import { useMint , withMint } from '@senhub/providers'
Copy 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)
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.
Copy 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 ;
}
Copy 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: []
// },
// ...
// ]
Copy 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: []
// }
Copy 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: []
// },
// ]