Appearance
etxn_fee_base
Summary. Compute the minimum fee (in drops) that a to-be-emitted transaction must pay, given its fully-serialized form.
Signature.
c
int64_t etxn_fee_base(uint32_t read_ptr, uint32_t read_len);Parameters.
| Name | Type | Description |
|---|---|---|
read_ptr | uint32_t | Pointer to the serialized transaction. |
read_len | uint32_t | Length of the serialized transaction. |
Return value. Returns the required fee in drops on success. Errors: OUT_OF_BOUNDS (-1) for a bad buffer; PREREQUISITE_NOT_MET (-9) if etxn_reserve was not called; INVALID_TXN (-37) if the buffer cannot be parsed as a transaction.
Common failure patterns.
- Calling it before
etxn_reserve→PREREQUISITE_NOT_MET. - Passing a malformed or incomplete transaction blob →
INVALID_TXN.
Caveats / notes.
- Internally this runs the transaction through the same base-fee calculation the network uses (
calculateBaseFee/invoke_calculateBaseFeeunderfixHookAPI20251128), so it doubles as a sanity check that the blob is a valid transaction. - Compute the fee after the transaction is otherwise complete (including
sfEmitDetails), then write the returned value intosfFee.emitrejects a transaction whosesfFeeis below this minimum withEMISSION_FAILURE.
Minimal example.
c
int64_t fee = etxn_fee_base((uint32_t)tx, tx_len);Practical example (the pattern generated by the Transaction Builder).
c
// After the template is otherwise complete (including sfEmitDetails),
// compute the fee and patch it into sfFee via the generated FEE_OUT pointer.
int64_t fee = etxn_fee_base(SBUF(txn));
if (fee < 0)
rollback(SBUF("fee calc failed"), fee);
SET_NATIVE_AMOUNT(FEE_OUT, fee);This is exactly what the generated PREPARE_TXN() macro does for you — see Emitted Transaction.