1

I want to create an Account using SOL contained in a PDA. For that I guess I need two signatures, the payer(master) that will pay for the CPI call and the rent, and the receiver(subordinate).

How do I achieve that with the .with_signers()?

            let rent = Rent::get()?;
        let size = size_of::<Subordinate>() + 8;
        let min_lamport_rent = rent.minimum_balance(size);

        let bump = &[ctx.bumps.surbordinate];
        let seeds = &[b"subordinate".as_ref(), bump];
        let signer_seeds = &[&seeds[..]];

        let cpi_accounts = CreateAccount {
            from: ctx.accounts.master.to_account_info(),
            to: ctx.accounts.subordinate.to_account_info(),
        };

        let cpi_context =
            CpiContext::new(ctx.accounts.system_program.to_account_info(), cpi_accounts)
                .with_signer(signer_seeds);

        create_account(
            cpi_context,
            min_lamport_rent,
            size.try_into().unwrap(),
            ctx.program_id,
        )?;
3
  • Duplicate question. An answer can be found here: solana.stackexchange.com/questions/3002/…
    – PandaPanda
    Commented Jan 21 at 23:50
  • Is the master account a PDA or a wallet?
    – wei1769
    Commented Jan 22 at 3:18
  • Both are PDA, the question was about how to sign a CPI when multiples signers are involved. Cheers!
    – PandaPanda
    Commented Jan 22 at 13:03

0

Your Answer

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

Browse other questions tagged or ask your own question.