0

I've encountered a problem trying to reuse an old project. I'm trying to build the project but the cli throws this error at me: "this is an associated function, not a method" for using *ctx.bumps.get("treasury_account").unwrap();

I hope someone can help me. Thank you!

    pub fn init_treasury(ctx: Context<InitAccounts>) -> Result<()> {
    msg!("treasury account");
    ctx.accounts.treasury_account.bump = *ctx.bumps.get("treasury_account").unwrap();

    Ok(())
}


#[derive(Accounts)]
pub struct InitAccounts<'info> {
    #[account(mut)]
    pub payer: Signer<'info>,
    #[account(init, payer = payer, space = 8+1, seeds=[b"treasury"], bump)]
    pub treasury_account: Account<'info, TreasuryAccount>,
    pub system_program: Program<'info, System>,
}

#[account]
pub struct TreasuryAccount {
    pub bump: u8,
}

1 Answer 1

1

To get the canonical bump of the treasury_account

    let treasury_account = &mut ctx.accounts.treasury_account;
    treasury_account.bump = ctx.bumps.treasury_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.