Skip to main content

SPL token program composability libraries

Repository​

SPL Token program Solidity libraries

Exmaple contract​

CallSPLTokenProgram - example contract demonstrating how the SPL Token program Solidity libraries can be used in practice to interact with Solana's SPL Token program.

SPL Token program libraries​

LibSPLTokenProgram library​

This library provides helper functions for formatting instructions to be executed by Solana's SPL Token program.

Available SPL Token program instructions​

  • initializeMint2: initializes a Solana account as a SPL token mint. Such an account holds data related to a SPL token (see LibSPLTokenData.SPLTokenMintData). See instruction formatting.

  • initializeAccount2: initializes a Solana account as a SPL token account. Such an account holds data related to a SPL token holder (see LibSPLTokenData.SPLTokenAccountData). See instruction formatting.

  • mintTo: mints an amount of tokens to an initialized SPL token account. See instruction formatting.

  • transfer: transfers an amount of tokens to an initialized SPL token account. See instruction formatting.

  • setAuthority: updates a SPL token mint's MINT or FREEZE authority or a a SPL token account's OWNER or CLOSE authority. See instruction formatting.

  • approve: delegates an amount of tokens belonging to a SPL token account to a third party Solana account. See instruction formatting.

  • revoke: revokes token delegation previously granted to a third party Solana account. See instruction formatting.

  • burn: burns an amount of tokens from a SPL token account. See instruction formatting.

  • closeAccount: closes a previously initialized SPL token account. See instruction formatting.

  • syncNative: syncs the token balance of a Wrapped SOL token account to reflect its SOL balance (minus rent exemption balance). See instruction formatting.

LibSPLTokenData library​

This library provides a set of getter functions for querying SPL Token accounts data from Solana.

SPL token mint data​

The following data fields are stored by SPL token mint accounts and can be queried using the LibSPLTokenData library:

bytes4 mintAuthorityOption
bytes32 mintAuthority
uint64 supply
uint8 decimals
bool isInitialized
bytes4 freezeAuthorityOption
bytes32 freezeAuthority

SPL token account data​

The following data fields are stored by SPL _token account_s and can be queried using the LibSPLTokenData library:

bytes32 mint
bytes32 owner
uint64 balance
bytes4 delegateOption
bytes32 delegate
bool isInitialized
bytes4 isNativeOption
bool isNative
uint64 delegatedAmount
bytes4 closeAuthorityOption
bytes32 closeAuthority

LibSPLTokenErrors library​

This library provides a set of custom errors that may be thrown when using LibSPLTokenProgram and LibSPLTokenData libraries.

Was this page helpful?