2

If I want to use instruction data in my account constraints, I can do it like so:

#[derive(Accounts)]
#[instruction(my_param: u32)]
pub struct MyAccounts<'info> {
    #[account(
        seeds = [my_param.to_le_bytes().as_ref()],
        bump
    )]
    pub my_account: Account<'info, MyAccount>,
}

Let's say I want to use multiple params. Intuitively, I tried the below:

#[derive(Accounts)]
#[instruction(my_param: u32)]
#[instruction(my_second_param: u32)]
pub struct MyAccounts<'info> {
    #[account(
        seeds = [my_param.to_le_bytes().as_ref(), my_second_param.to_le_bytes().as_ref()],
        bump
    )]
    pub my_account: Account<'info, MyAccount>,
}

This gives me the error cannot find value "my_second_param" in this scope. Is there a way to achieve this out of the box (which isn't merging my two params into a struct)? Or does anchor only allow one instruction constraint?

1 Answer 1

2

Turns out I'm just an idiot :)

The way to do this is simply writing all the instruction vars inside the constraint:

#[derive(Accounts)]
#[instruction(my_param: u32, my_second_param: u32)]
pub struct MyAccounts<'info> {
    #[account(
        seeds = [my_param.to_le_bytes().as_ref(), my_second_param.to_le_bytes().as_ref()],
        bump
    )]
    pub my_account: Account<'info, MyAccount>,
}

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.