Why This Matters
Solana programs can fetch rent in two ways:
Instructions that rely on the Rent sysvar account internally use
Rent::from_account_info(), which behaves like Rent::default() and returns Solana’s hardcoded rent values. This causes 100x overpayment on Solayer Chain.
Token Program Instructions
The original Token Program includes both legacy instructions (which use the Rent sysvar) and newer variants (which use theRent::get() syscall).
Instructions to Avoid
Recommended Instructions
Token 2022 Instructions
Token 2022 (Token Extensions) follows the same pattern. Always use the “V2” or “V3” variants.Instructions to Avoid
Recommended Instructions
Important for Token 2022: Account sizes vary based on enabled extensions. Always calculate sizes dynamically rather than hardcoding values.
Code Examples
Creating a Mint with InitializeMint2 (TypeScript)
Creating a Token Account with InitializeAccount3 (TypeScript)
Token 2022 with Extensions (TypeScript)
Rust: Correct vs Incorrect Rent Usage
When writing custom Solana programs, always useRent::get() instead of Rent::default().
Best Practices Summary
-
Always query rent from the chain
-
Use “V2” or “V3” instruction variants - They use the
Rent::get()syscall internally -
Calculate account sizes dynamically for Token 2022 - Use
getMintLen()andgetAccountLen()with your extensions -
In Rust programs, use
Rent::get()- Never useRent::default()which returns hardcoded values
Quick Reference
Safe Instructions (use Rent::get() syscall)
InitializeMint2InitializeAccount2InitializeAccount3InitializeMultisig2
Instructions to Avoid (use Rent sysvar)
InitializeMintInitializeAccountInitializeMultisig