2

I am trying to determine if it is possible to determine the transaction fee from within the program itself?

In solidity we have gasleft() which allows us to take snapshots at the beginning and end of the transaction. We can then multiply this value, with an additional buffer, with tx.gasprice.

Is there something similar for solana? Thanks

1 Answer 1

1

Transaction fees are known before you call the transaction in Solana. What isn't known is the amount of compute units you may use, though this does not currently affect pricing. You can request up to 1.4M compute units. 5000 Lamports is the current cost of a transaction without priority fees -- you can add an additional priority fee to the transaction if you wish, which will help during times of high traffic.

3
  • I see. My intention is to remove the trust assumption where the chain is the oracle instead of the sender. It seems the calculation is (base_fee * trx_signatures) + (compute_units * priority_fee_per_compute_unit). Is there a way of determining any of these values (besides signatures) within the program itself?
    – Nat
    Commented Jan 2 at 16:06
  • base_fee is known. compute units is what is requested (allocated), not what ends up being used (you can use less, it still costs whatever you set up front). you can probably see how much compute has been requested via introspection, though i'm not sure what that would look like off hand.
    – joebuild
    Commented Jan 2 at 16:37
  • Maybe these settings are stored in the core program and can be referenced that way.
    – Nat
    Commented Jan 2 at 18:09

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.