spl_token

Module for getting account addresses of SPL tokens.

class SplTokenConst

Bases: object

Class container for SPL token constants.

DEF_PROGRAM_ID: str = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'
DEF_TOKEN_PROGRAM_ID: str = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
PDA_MARKER: bytes = b'ProgramDerivedAddress'
SEED_BUMP_MAX_VAL: int = 255
SEEDS_MAX_NUM: int = 16
class SplToken

Bases: object

SPL token class. It provides methods for getting the account address associated to a SPL token.

classmethod GetAssociatedTokenAddress(wallet_addr: str, token_mint_addr: str) str

Get the account address associated to the specified SPL token.

Parameters:
  • wallet_addr (str) – Wallet address

  • token_mint_addr (str) – Token mint address

Returns:

Associated account address

Return type:

str

Raises:

ValueError – If the account address cannot be found or the specified addresses are not valid

classmethod GetAssociatedTokenAddressWithProgramId(wallet_addr: str, token_mint_addr: str, token_program_id: str) str

Get the account address associated to the specified SPL token and token program ID.

Parameters:
  • wallet_addr (str) – Wallet address

  • token_mint_addr (str) – Token mint address

  • token_program_id (str) – Token program ID

Returns:

Associated account address

Return type:

str

Raises:

ValueError – If the account address cannot be found or the specified addresses or ID are not valid

classmethod FindPda(seeds: List[bytes], program_id: str) str

Find a valid PDA (Program Derived Address) and its corresponding bump seed.

Parameters:
  • seeds (list[bytes]) – List of seeds bytes

  • program_id (str) – Program ID

Returns:

Found PDA

Return type:

str

Raises:

ValueError – If the PDA cannot be found or the specified seeds or program ID are not valid