1

I am getting this error when using anchor build.

error[E0433]: failed to resolve: use of undeclared crate or module system_program --> programs/account_data_program/src/instructions/create.rs:22:4 | 22 | system_program::create_account( | ^^^^^^^^^^^^^^ use of undeclared crate or module `system_program

Any ideas to why this crate isn't declared?


use anchor_lang::prelude::*;


use crate::state::AddressInfo;


pub fn create_address_info(
    ctx: Context<CreateAddressInfo>,
    name: String,
    house_number: u8,
    street: String,
    city: String,
) -> Result<()> {
    let address_info = AddressInfo::new(name, house_number, street, city);
    
    let account_span = (address_info.try_to_vec()?).len();
    let lamports_required = (Rent::get()?).minimum_balance(account_span);
    
    
   system_program::create_account(
        CpiContext::new(
            ctx.accounts.system_program.to_account_info(),
            system_program::CreateAccount {
                from: ctx.accounts.payer.to_account_info(),
                to: ctx.accounts.address_info.to_account_info(),
            },
        ),
        lamports_required,
        account_span as u64,
        &ctx.accounts.system_program.key(),
    )?;

    let address_info_account = &mut ctx.accounts.address_info;
    address_info_account.set_inner(address_info);
    Ok(())
}

#[derive(Accounts)]
pub struct CreateAddressInfo<'info> {
    #[account(mut)]
    address_info: Account<'info, AddressInfo>,
    #[account(mut)]
    payer: Signer<'info>,
    system_program: Program<'info, System>,
}

1 Answer 1

3

you have system_program:: used but you need to import it

use anchor_lang::solana_program::system_program;

But this does not has create_account

use anchor_lang::solana_program::system_instruction::create_account;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.