Function multisig_lite::multisig_lite::create_transfer
source · pub fn create_transfer(
ctx: Context<'_, '_, '_, '_, CreateTransfer<'_>>,
recipient: Pubkey,
lamports: u64,
fund_bump: u8
) -> Result<()>
Expand description
Creates a queued transfer lamports to the recipient.
Transfer account creation fee will be given back to the creator of the transfer from the multisig fund.
Examples
Here is how to create a pending transfer on Devnet:
use std::rc::Rc;
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::native_token::LAMPORTS_PER_SOL;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::read_keypair_file;
use solana_sdk::signer::{keypair::Keypair, Signer};
use solana_sdk::system_program;
use anchor_client::{Client, Cluster};
let url = Cluster::Devnet;
let funder = Rc::new(read_keypair_file(
shellexpand::tilde("~/.config/solana/id.json").as_ref(),
)?);
let opts = CommitmentConfig::processed();
let pid = multisig_lite::id();
let program = Client::new_with_options(url, funder.clone(), opts).program(pid);
// Gets the PDAs.
let (state_pda, state_bump) =
Pubkey::find_program_address(&[b"state", funder.pubkey().as_ref()], &pid);
let (fund_pda, fund_bump) = Pubkey::find_program_address(&[b"fund", state_pda.as_ref()], &pid);
// Temporary transfer keypair.
//
// This is only required for the transaction signature and
// won't be required once the transaction is recorded on the
// ledger.
let transfer = Keypair::new();
// Creates a pending transfer.
let sig = program
.request()
.accounts(multisig_lite::accounts::CreateTransfer {
creator: funder.pubkey(),
state: state_pda,
fund: fund_pda,
transfer: transfer.pubkey(),
system_program: system_program::id(),
})
.args(multisig_lite::instruction::CreateTransfer {
recipient: Pubkey::new_unique(),
lamports: 1_000_000 * LAMPORTS_PER_SOL, // 1M SOL!? :)
fund_bump,
})
.signer(funder.as_ref())
.signer(&transfer)
.send()?;
println!("{sig}");