# Cannot calculate suggested fees for inner transactions

**URL:** https://forum.algorand.co/t/cannot-calculate-suggested-fees-for-inner-transactions/5826
**Category:** General
**Tags:** smart-contracts
**Created:** [January 22, 2022, 8:05am UTC](https://forum.algorand.co/t/cannot-calculate-suggested-fees-for-inner-transactions/5826 "2022-01-22T08:05:41Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![plasmatech8](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@plasmatech8](https://forum.algorand.co/u/plasmatech8)
#### Post date: [February 2, 2022, 2:21am UTC](https://forum.algorand.co/t/cannot-calculate-suggested-fees-for-inner-transactions/5826/9 "2022-02-02T02:21:51Z")

</div>

I have made an [gh issue](https://github.com/algorand/go-algorand/issues/3534) and I think it clarified a few things for me as well.

The `fee` parameter (fee-per-byte) returned by the API is indeed correct (it is zero until network congestion occurs). The fee-per-byte is NOT a problem.

## Is this a bug?

As stated above, `suggested_params.min_fee` has no effect when passed into a transaction contructor (`sp=suggested_params`).

The reason for this is because `py-algorand-sdk` uses a constant (`constants.min_txn_fee`) instead of the min-fee which is stored in the object (`sp.min_fee`).

```python
if not sp.flat_fee:
    self.fee = max(
        self.estimate_size() * self.fee, constants.min_txn_fee
    )

```

I do not know if this is intentional or not, but it does make it so that the user cannot specify the minimum fee - and you need to use a flat fee instead.

## How to calculate fees for inner transactions

For the time-being, if:

- You have inner transactions (with fees paid by the user)
- You want to make sure that your transactions adapt to increased fee-per-byte (due to network congestion)
- You want it to work with specific number of inner transactions

Then you need to do something like the following:

```python
# Get txn info

num_bytes = transaction.ApplicationNoOpTxn(
    sender=sender.address,
    sp=client.suggested_params(),
    index=application_id,
    app_args=['return_to_sender']
).estimate_size()
num_txns = 5 # hard coded (1 outer + 4 inner)

# Calculate fee & get suggested params

suggusted_params = client.suggested_params()
suggusted_params.fee = max(
    num_bytes * suggested_params.fee, # fee-per-byte
    num_txns * suggusted_params.min_fee # min-fee
)
suggusted_params.flat_fee = True

# Construct transaction

txn = transaction.ApplicationNoOpTxn(
    sender=sender.address,
    sp=suggusted_params,
    index=application_id,
    app_args=['return_to_sender']
)

# ... 
# sign and send

```

(I have not tested)

Otherwise, for 99% of cases, the simple answers will work fine.

I would be convenient to use `suggested_parameters.min_fee` though.

---

_[View the full topic](https://forum.algorand.co/t/cannot-calculate-suggested-fees-for-inner-transactions/5826)._
