# Mint Provider

## API

```tsx
<MintProvider> ... </MintProvider>
```

| Property | Type      | Description           | Default   |
| -------- | --------- | --------------------- | --------- |
| children | ReactNode | The wrapped children. | undefined |

#### For example

```tsx
import { MintProvider } from '@sentre/senhub'

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

## Context

```typescript
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

| 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](#undefined) for details. |

#### MintData

| 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. |

## Hook & HOC

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

#### For example

{% hint style="info" %}
Wrap the parent by MintProvider before accessing the context.
{% endhint %}

```tsx
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

{% hint style="info" %}
In this document, we will use token and mint interchangeably. However, the meaning of both is the same.
{% endhint %}

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

| 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.                                                 |

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

#### TokenInfo

```typescript
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

```typescript
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

```typescript
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

```typescript
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: []
//    },
// ]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sentre.io/development/providers/mint-provider.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
