3

Hi I am struggling to understand how to make token accounts rent exempt.

I have used the following code to create my token account for an SPL token lifted out of the Solana docs. I see that Solana is debited from my account when I create them (payer in the code). Are these account all rent exempt by default or do I have to put in additional Solana to make them rent exempt?

 const tokenAccount = await getOrCreateAssociatedTokenAccount(
        connection,
        payer,
        mint,
        payer.publicKey
      )

If I do have to put in additional Solana please share how. Also does the same hold true for mint accounts etc...

2 Answers 2

4

The solana runtime now enforces that all accounts are rent exempt by default. So if you successfully created an account, then it's definitely rent exempt!

The code you linked looks like it's from the spl token web3 library. Don't worry, it's a well written library that will create accounts properly for you with the correct amount of solana to ensure they're rent exempt. You can always check the source if you want to understand more.

2

In this case the associated token account program handles the transfer of the rent-exempt-reserve balance and will fail if the funding account cannot afford it. Similarly, for auxiliary token accounts, the initialize instruction will fail if the account being initialized does not hold enough lamports to maintain rent-exemption

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.