1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #![allow(clippy::result_large_err)]
- use anchor_lang::prelude::*;
- use anchor_lang::system_program::{create_account, CreateAccount};
- declare_id!("ARVNCsYKDQsCLHbwUTJLpFXVrJdjhWZStyzvxmKe2xHi");
- #[program]
- pub mod create_system_account {
- use super::*;
- pub fn create_system_account(ctx: Context<CreateSystemAccount>) -> Result<()> {
- msg!("Program invoked. Creating a system account...");
- msg!(
- " New public key will be: {}",
- &ctx.accounts.new_account.key().to_string()
- );
- // The minimum lamports for rent exemption
- let lamports = (Rent::get()?).minimum_balance(0);
- create_account(
- CpiContext::new(
- ctx.accounts.system_program.to_account_info(),
- CreateAccount {
- from: ctx.accounts.payer.to_account_info(), // From pubkey
- to: ctx.accounts.new_account.to_account_info(), // To pubkey
- },
- ),
- lamports, // Lamports
- 0, // Space
- &ctx.accounts.system_program.key(), // Owner Program
- )?;
- msg!("Account created succesfully.");
- Ok(())
- }
- }
- #[derive(Accounts)]
- pub struct CreateSystemAccount<'info> {
- #[account(mut)]
- pub payer: Signer<'info>,
- #[account(mut)]
- pub new_account: Signer<'info>,
- pub system_program: Program<'info, System>,
- }
|