In my program I'm trying to init PDA Token Accounts so that my program can store tokens of specified mints like this:
#[derive(Accounts)]
pub struct StartAuction<'info> {
#[account(init, seeds=[&state.positions_count.to_ne_bytes()], bump, payer = authority, space = 5000)]
pub position: Account<'info, Position>,
#[account(mut, seeds=[b"state"], bump)]
pub state: Account<'info, State>,
pub token: Account<'info, Mint>,
pub token2: Account<'info, Mint>,
#[account(init, payer = authority, token::mint = token, token::authority = position)]
pub vault: Account<'info, TokenAccount>,
// #[account(init, payer = authority, token::mint = token2, token::authority = position)]
// pub token2_vault: Account<'info, TokenAccount>,
#[account(mut)]
pub authority: Signer<'info>,
pub token_program: Program<'info, Token>,
pub rent: Sysvar<'info, Rent>,
pub system_program: Program<'info, System>
}
If the token2_vault
account is commented like shown above everything is good. But when I uncomment it (to have two Token Accounts for different mints), I'm getting a confusing error: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0.
Assuming that this is the NotRentExempt
("Lamport balance below rent-exempt threshold") SPL Error as specified here and given that the authority
account definitely has enough lamports, it's completely unclear why I can init one account but not two, with such strange error.
Thanks in advance!
I solved it by adding seeds to the accounts definitions, like this:
#[derive(Accounts)]
pub struct StartAuction<'info> {
#[account(init, seeds=[b"vault1".as_ref()], payer = authority, token::mint = token, token::authority = position)]
pub vault: Account<'info, TokenAccount>,
#[account(init, seeds=[b"vault2".as_ref()], payer = authority, token::mint = token2, token::authority = position)]
pub token2_vault: Account<'info, TokenAccount>
}
I guess without defining seeds those two accounts had the same address which caused the error. Why this generates the 0x0 NotRentExempt
error is still not clear.