When making CPI calls in my program, I am wondering whether I pay for the transaction cost associated with it.

To my understanding my program execution is paused and it goes to executing the cpi-ed program. what if this program fails, e.g an error arises. what happens to the fees I paid? Does it roll back?

1 Answer 1


Payer of the transaction pays for the CPI calls as well.

Failed transactions, including those that fail due to a CPI call, still pay transaction fees.

The two main reasons are:

  • the transaction was executed by the leader validator so it consumed resources regardless of it's failure

  • it prevents spam/DDOS attacks that would be possible if failed transactions were free for the sender. With free transactions, an attacker could simply flood the network making it unusable.

Thankfully, Solana lets you simulate a transaction before sending it, this helps to avoid errors and wasted fees.


Before submitting, the following preflight checks are performed:

    The transaction signatures are verified
    The transaction is simulated against the bank slot specified by the preflight commitment. On failure an error will be returned. Preflight
  • 2
    To add to the answer and address your last question concretely: yes, state gets rolled back if there's an error in a CPI call. If a CPI call produces an error, there's no way to recover, and the entire transaction is aborted immediately, without any changes persisted.
    – Jon C
    Commented Sep 20, 2023 at 9:56

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.