initializeMultisig static method
Initializes a multisignature account with N provided signers.
Multisignature accounts can used in place of any single owner/delegate accounts in any token instruction that require an owner/delegate to be present. The variant field represents the number of signers required to validate this multisignature account.
The initializeMultisig
instruction requires no signers and MUST be included within the same
Transaction as the system program's createAccount
instruction that creates the account being
initialized. Otherwise another party can acquire ownership of the uninitialized account.
Keys:
[w]
account
- The multisignature account to initialize.[]
signers
- The signer accounts (minSigners : maxSigners).
Data
numberOfSigners
- The number of signers required to validate this multisignature account.
Implementation
static TransactionInstruction initializeMultisig({
// Keys
required final Pubkey account,
required final List<Pubkey> signers,
// Data
required final u8 numberOfSigners,
}) {
// Validation
checkGte(signers.length, minSigners, 'signers');
checkLte(signers.length, maxSigners, 'signers');
// 0. `[w]` The multisignature account to initialize.
// 1. `[]` Rent sysvar.
// 2. `[]` ..2+N The signer accounts, must equal to N where 1 <= N <= 11.
final List<AccountMeta> keys = [
AccountMeta.writable(account),
AccountMeta(sysvarRentPubkey),
for (final Pubkey signer in signers) AccountMeta(signer),
];
final List<Iterable<int>> data = [
borsh.u8.encode(numberOfSigners),
];
return _instance.createTransactionIntruction(
TokenInstruction.initializeMultisig,
keys: keys,
data: data,
);
}