findAssociatedTokenAddress method

Future<Ed25519HDPublicKey> findAssociatedTokenAddress(
  1. Ed25519HDPublicKey ownerPubKey,
  2. Ed25519HDPublicKey mintPubKey
)

Find associated token addres

Functionality

Finds the address of the associated token account for a given mint and owner.

Parameters

Ed25519HDPublicKey ownerPublicKey Ed25519HDPublicKey mintPublicKey

Return

Ed25519HDPublicKey from programAddress

Implementation

Future<solana.Ed25519HDPublicKey> findAssociatedTokenAddress(
    solana.Ed25519HDPublicKey ownerPubKey,
    solana.Ed25519HDPublicKey mintPubKey) async {
  final solana.Ed25519HDPublicKey binaryKey =
      solana.Ed25519HDPublicKey(base58decode(Constants.TOKEN_PROGRAM_ID));

  return solana.Ed25519HDPublicKey.findProgramAddress(
    seeds: [
      ownerPubKey.toByteArray(),
      binaryKey.toByteArray(),
      mintPubKey.toByteArray(),
    ],
    programId: solana.Ed25519HDPublicKey.fromBase58(
        Constants.ASSOCIATED_TOKEN_PROGRAM_ID),
  );
}