pub fn withdraw_nonce_account(
nonce_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
to_pubkey: &Pubkey,
lamports: u64
) -> Instruction
Expand description
Withdraw lamports from a durable transaction nonce account.
This function produces an Instruction
which must be submitted in a
Transaction
or invoked to take effect, containing a serialized
SystemInstruction::WithdrawNonceAccount
.
Withdrawing the entire balance of a nonce account will cause the runtime to destroy it upon successful completion of the transaction.
Otherwise, nonce accounts must maintain a balance greater than or equal to the minimum required for rent exemption. If the result of this instruction would leave the nonce account with a balance less than required for rent exemption, but also greater than zero, then the transaction will fail.
This constructor creates a SystemInstruction::WithdrawNonceAccount
instruction.
§Required signers
The authorized_pubkey
signer must sign the transaction.
§Examples
use solana_rpc_client::rpc_client::RpcClient;
use solana_sdk::{
pubkey::Pubkey,
signature::{Keypair, Signer},
system_instruction,
transaction::Transaction,
};
use anyhow::Result;
fn submit_withdraw_nonce_account_tx(
client: &RpcClient,
nonce_account_pubkey: &Pubkey,
authorized_account: &Keypair,
) -> Result<()> {
let nonce_balance = client.get_balance(nonce_account_pubkey)?;
let instr = system_instruction::withdraw_nonce_account(
&nonce_account_pubkey,
&authorized_account.pubkey(),
&authorized_account.pubkey(),
nonce_balance,
);
let mut tx = Transaction::new_with_payer(&[instr], Some(&authorized_account.pubkey()));
let blockhash = client.get_latest_blockhash()?;
tx.try_sign(&[authorized_account], blockhash)?;
client.send_and_confirm_transaction(&tx)?;
Ok(())
}