setAuthority static method

TransactionInstruction setAuthority({
  1. required Pubkey account,
  2. required Pubkey authority,
  3. List<Pubkey> signers = const [],
  4. required AuthorityType authorityType,
  5. required Pubkey? newAuthority,
})

Sets a new authority of a mint or account.

Keys:

Single authority

  • [w] account - The mint or account to change the authority of.
  • [s] authority - The current authority of the mint or account.

Multisignature authority

  • [w] account - The mint or account to change the authority of.
  • [] authority - The mint's or account's current multisignature authority.
  • [s] signers - The signer accounts.

Data:

  • authorityType - The type of authority to update.
  • newAuthority - The new authority.

Implementation

static TransactionInstruction setAuthority({
  // Keys
  required final Pubkey account,
  required final Pubkey authority,
  final List<Pubkey> signers = const [],
  // Data
  required final AuthorityType authorityType,
  required final Pubkey? newAuthority,
}) {
  // * Single authority
  // 0. `[w]` The mint or account to change the authority of.
  // 1. `[s]` The current authority of the mint or account.
  //
  // * Multisignature authority
  // 0. `[w]` The mint or account to change the authority of.
  // 1. `[]` The mint's or account's current multisignature authority.
  // 2. `[s]` ..2+M, M signer accounts.
  final List<AccountMeta> keys = [
    AccountMeta.writable(account),
    AccountMeta(authority, isSigner: signers.isEmpty),
    for (final Pubkey signer in signers)
      AccountMeta.signer(signer),
  ];

  final List<Iterable<u8>> data = [
    borsh.enumeration(AuthorityType.values).encode(authorityType),
    borsh.pubkey.option().encode(newAuthority?.toBase58()),
  ];

  return _instance.createTransactionIntruction(
    TokenInstruction.setAuthority,
    keys: keys,
    data: data,
  );
}