withdraw static method
Withdraw unstaked lamports from the stake account.
Keys:
[w]
stakeAccount
- Stake account from which to withdraw.[w]
recipientAccount
- Recipient account.[s]
withdrawAuthority
- Withdraw authority.[s]
custodian
- Lockup authority, if before lockup expiration.
Data:
lamports
- The portion of the stake account balance to be withdrawn.
Implementation
static TransactionInstruction withdraw({
// Keys
required final Pubkey stakeAccount,
required final Pubkey recipientAccount,
required final Pubkey withdrawAuthority,
final Pubkey? custodian,
// Data
required final bu64 lamports,
}) {
// 0. `[w]` Stake account from which to withdraw
// 1. `[w]` Recipient account
// 2. `[]` Clock sysvar
// 3. `[]` Stake history sysvar that carries stake warmup/cooldown history
// 4. `[s]` Withdraw authority
// 5. `[s]` Lockup authority, if before lockup expiration
final List<AccountMeta> keys = [
AccountMeta.writable(stakeAccount),
AccountMeta.writable(recipientAccount),
AccountMeta(sysvarClockPubkey),
AccountMeta(sysvarStakeHistoryPubkey),
AccountMeta.signer(withdrawAuthority),
if (custodian != null) AccountMeta.signer(custodian),
];
final List<Iterable<u8>> data = [
borsh.u64.encode(lamports),
];
return _instance.createTransactionIntruction(
StakeInstruction.withdraw,
keys: keys,
data: data,
);
}