1

I understand how to calculate deployment cost using `solana rent <DATA_LENGTH>. But how do I calculate lamports needed to upgrade program?

1 Answer 1

2

Program upgrades are tricky to price. You need to have enough SOL for the rent-exemption of the new program buffer account, which is roughly the same as solana rent <DATA_LENGTH>, but this gets refunded to you after the upgrade is successful.

In the end, you only need to pay the transaction fees to create and write to the new program buffer account, and then a transaction to finalize the upgrade, which is dependent on the size of the program.

I tested a program that takes 335 transactions to execute, and the upgrade cost 1690000 lamports. Since you've got 1 transaction to create the buffer (10000 lamports since you need to sign for the buffer account), 335 transactions to write (5000 lamports since there's only one signer), and 1 transaction to finalize (5000 lamports as well), that comes out to 336 transactions at 5000 lamports, and 1 transaction at 10000 lamports, which is exactly it:

336 * 5000 + 10000 = 1690000

Maybe we should have a tool to estimate this...

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.