How are fees calculated in Solana ?
1 Answer
Solana Instructions have a non-fixed fee but usually 5000 Lamports (currently) A Transaction can have multiple instructions.
But Data Allocation cost is calculated
Solana defines a constant cost as 1 byte per year and being rent exempt if you exceed 2 years. so
/// default rental rate in lamports/byte-year:
pub const DEFAULT_LAMPORTS_PER_BYTE_YEAR: u64 = 1_000_000_000 / 100 * 365 / (1024 * 1024);
/// default amount of time (in years) the balance has to include rent for:
pub const DEFAULT_EXEMPTION_THRESHOLD: f64 = 2.0;
Allocating 500 bytes will cost 500 * DEFAULT_LAMPORTS_PER_BYTES_YEAR * DEFAULT_EXEMPTION_THRESHOLD
Lamports
Plus 5000 Lamports for the instruction
which is around ~0.007 Sol
you can do the same to calculate the fee for creating a token account
(165 bytes) mint etc... You can automate this process with getMinimumBalanceForRentExemption
another example: How much sol is required to mint 1000 items using sugar candy machine?