Calculating TRX gas fee for a transaction/account

1k views Asked by At

Hi i was sending a transaction on python with tronpy library, but anytime i try to send it. using the library it throws out an error saying out of balance which makes sense because i send the full amount. so

txn = client.trx.transfer('from wallet', 'to wallet', int(balance * 1000_000)).build().sign(priv_key).inspect().broadcast()

multiplying here with 1 million because of the decimal points in TRX money is 6 zeros. so also when i query 'wallet/getaccountnet' i think the calculation is being made from there im using testnet also mainnet but depending on the table it shows here: \n

api\n It does not return the full details that being showed in the table so im confused where can i get the transaction fee for given trx address

this is how i calculate the bandwidth from tron api 'wallet/getaccountnet':

(bandwidth['freeNetLimit'] - bandwidth['freeNetUsed']) + (bandwidth['NetLimit'] - bandwidth['NetUsed'])

Api i've provided does not return the full details that being showed in the table so im confused where can i get the transaction fee for given trx address

1

There are 1 answers

1
Michael Knepper On BEST ANSWER

I also encountered the same issue, the most relatable solution I could find is as follows:

trontxsize library

In Tron (TRX) network, fee calculation algorithm is complex. And the most complex part of it is that it depends on transaction size.

But there's no method existing to calculate it

This library does just this:

import trontxsize

print(trontxsize.get_tx_size({"raw_data": ..., "signatures": [...])) # matches bandwidth you see in block explorer

How does it work? The library pre-compiled a trimmed-down version of Tron protobuf and uses it directly to calculate transaction size.

The Tronpy guide on PYPI mentioned:

In case you want to use cryptocurrency functions in an universal way or e.g. reliably calculate transaction fees for BTC, ETH, Tron and many others, check out the BitcartCC project.

Yet again, I couldn't find a helpful way around, I hope these help and please let me know if you could find a solution.