Account Provider
🏦 SPL Accounts Provider
API
<AccountProvider> ... </AccountProvider>
children
ReactNode
The wrapped children.
undefined
For example
import { AccountProvider } from '@sentre/senhub'
// Wrap a paragraph as a child.
<AccountProvider>
<p>Hello world</p>
</AccountProvider>
Context
type Provider = {
accounts: State
}
type State = Record<string, AccountData>
type AccountData = {
mint: string;
owner: string;
amount: bigint;
delegate_option: number;
delegate: string;
state: number;
is_native_option: number;
is_native: bigint;
delegated_amount: bigint;
close_authority_option: number;
close_authority: string;
}
Provider
accounts
Record<string, AccountData>
A mapping from an account address to the corresponding account data.
AccountData
mint
string
The corresponding mint address to the account.
owner
string
The account owner address.
amount
bigint
The number of tokens.
delegate_option
0 | 1
Whether the delegate property is available.
delegate
string
The delegate address.
delegated_amount
bigint
The number of delegated tokens.
state
0 | 1 | 2
0: Uninitialized; 1: Initialized; 2: Frozen;
is_native_option
0 | 1
Whether the is_native property is available.
is_native
bigint
The number of wrapped lamports.
close_authority_option
0 | 1
Whether the close_authority property is available.
close_authority
string
The close authority address.
Hook & HOC
import { useAccount, withAccount } from '@senhub/providers'
For example
import { useAccount, withAccount } from '@senhub/providers'
// Within a functional component
const Component = () => {
const { accounts } = useAccount()
console.log(accounts['8kGbKrvS3zopf4ZJwNDhEKMbZ3iC4Jztn43MZ8Nabcxq'])
// mint: "sRHC8De9nks5KYQ7n2jYacsVgBKe9irc7vhpSzoAVYY"
// owner: "8UaZw2jDhJzv5V53569JbCd3bD4BnyCfBH3sjwgajGS9"
// amount: 10000000000000n
// delegate_option: 0
// delegate: "11111111111111111111111111111111"
// state: 1
// is_native_option: 0
// is_native: 0
// delegated_amount: 0n
// close_authority_option: 0
// close_authority: "11111111111111111111111111111111"
}
export default Component
// Within a class component
class Component {
render() {
const { accounts } = this.props
console.log(accounts['8kGbKrvS3zopf4ZJwNDhEKMbZ3iC4Jztn43MZ8Nabcxq'])
// mint: "sRHC8De9nks5KYQ7n2jYacsVgBKe9irc7vhpSzoAVYY"
// owner: "8UaZw2jDhJzv5V53569JbCd3bD4BnyCfBH3sjwgajGS9"
// amount: 10000000000000n
// delegate_option: 0
// delegate: "11111111111111111111111111111111"
// state: 1
// is_native_option: 0
// is_native: 0
// delegated_amount: 0n
// close_authority_option: 0
// close_authority: "11111111111111111111111111111111"
}
}
export default withAccount(Component)
Last updated