2

I want to calculate the minimum balance for Rent-except and have found code like this:

const { Connection, clusterApiUrl, LAMPORTS_PER_SOL } = require('@solana/web3.js');
const connection = new Connection(clusterApiUrl('mainnet-beta'), 'confirmed');

(async () => {
    const dataSize = 16; // Replace with the desired account size in bytes
    const minBalance = await connection.getMinimumBalanceForRentExemption(dataSize);
    console.log(`Rent-exempt minimum: ${minBalance / LAMPORTS_PER_SOL} SOL`);
})();

But what the data size that a wallet account (for example: normal accout on Phantom Wallet) use?

Also, I saw this code somewhere:

         Account {
            lamports: 100,
            data: data.to_vec(),
            owner: spl_token::id(),
            executable: false,
            rent_epoch: 0,
        };

Is the data size that use to compute rent just the size if above data field or the size of whole Account struct?

1 Answer 1

4

A normal system account for eg your wallet is just 0 bytes, so the rent-exempt balance is calculated from that.

For the Account struct you mentioned, it'd just be the size of that data field. So eg the number of lamports doesn't count for that. Everything except data has a fixed size, so the rent-exempt balance takes them into account and then just scales with data size.

1
  • Thanks for you answer and explaination. Apr 18 at 12:49

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.