4

I have this in my lib.rs file:

#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(
    init,
    payer = authority,
    space = 8 + Config::SIZE,
    seeds = ["config".as_bytes().as_ref()],
    bump 
)]
config: Box<Account<'info, Config>>,

#[account(mut)]
authority: Signer<'info>,
native_token_mint: Account<'info, Mint>,
system_program: Program<'info, System>,
rent: Sysvar<'info, Rent>

}

and in my test.ts file:

await program.methods
.initialize()
.accounts({
  config: configAddress,
  authority: admin.publicKey,
  nativeTokenMint: nativeMintAddress,
  //systemProgram: anchor.web3.SystemProgram.programId,
  //rent: anchor.web3.SYSVAR_RENT_PUBKEY
})
.signers([admin])
.rpc();

Running the test passes on the first try each time I rebuild and redeploy the program but fails everytime after that with the error above. I've checked and now I know that 0x0 means "Lamport balance below rent-exempt threshold" but I have no idea what that means and even if I did, how to solve this error.

1
  • instruction 0 is SystemInstruction::CreateAccount the system program's error 0 is AccountInUse, not sub-rent-exempt lamports balance
    – trent.sol
    Commented Aug 2, 2022 at 4:51

2 Answers 2

3

On the first call your accounts will be initialized. On subsequent calls, the initialization will naturally fail because the account is already initialized... :-) Did you expect a different behavior?

Also, better remove the comment marks for systemProgram and rent in the JS code, your instruction expects these.

2
  • Thanks. It had me stuck for a few days. What happened was I was creating a PDA account with only a constant seed. So I wasn't getting varying addresses on each test like I would if there was a different anchor.web3.Keypair.generate() account each time
    – Ademola
    Commented Aug 1, 2022 at 9:25
  • Ah got it. That I couldn't see from your question. Glad you solved it now. Commented Aug 1, 2022 at 22:45
1

To understand the errors you have to check the error.rs in solana library, this is the file: https://github.com/solana-labs/solana-program-library/blob/ea354ab358021aa08f774e2d4028b33ec56d4180/token/program/src/error.rs

Looks like you have "Lamport balance below rent-exempt threshold", I think you have to fund your account.

I hope this helps.

Errata:

By mistake I pointed out to an incorrect file thinking this was related to token program, the correct file is the one already pointed in the first comment by trent.sol:

https://github.com/solana-labs/solana/blob/a94920a4eadf1008fc292e47e041c1b3b0d949df/sdk/program/src/system_instruction.rs#L21-L22

2
  • the cited error references instruction index 0, which is a system program instruction, not an SPL Token program instruction. InstructionError:Custom(u32)'s value is defined by the program that declared the instruction which raised the error
    – trent.sol
    Commented Aug 2, 2022 at 6:18
  • 1
    Added an errata to explain the error Commented Aug 2, 2022 at 7:01

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.