[HELP] Calculating transaction fee in PHP and Javascript

The final part of the website I’m developing requires that there is a way to calculate a transaction fee in php and javascript. I found this equation on reddit

base_fee*max(1, 4*n_output+n_kernel-n_input)

i need help putting this together, where can i find what the base fee is, how do i come up with the rest of the information?

an alternative is if i can get the tx fee from the rust client before doing a send.

I guess I can leave the tx fee upto the rust client for sending from user wallets
when it comes to my blackjack game I could just put a maximum fee on the transaction, whats the maximum a transaction will cost?

tromp:base_fee*max(1, 4*n_output+n_kernel-n_input) is obsolete. it’s base_fee*(21*n_output+3*n_kernel+1*n_input)
and base_fee is half a milligrin

It’s all detailed in this RFC:

Can I calculate the fee without the wallet? because there seems to be no way to ask the rust client to estimate a fee.

There is a way to compute fee using Owner API. You can run init_send_tx method that will return you a Slate, inside of that Slate you will have computed fee. Of course you do not need to proceed with this Slate for the transaction. You can just use it as fee calculator.

so you are saying that i have to create a transaction every time i want to get a tx fee, that i have to cancel, just to create another exact same transaction this time knowing the fee amount.

can’t we just have an option in send to --estimate-fee which will just return the fee it would cost without having to create a transaction?

It has an estimate_only flag which would not actually initiate the transaction and change wallet state. It would only perform the computation required to form the slate but no outputs would be locked and no need to cancel anything.

Trade ogre … am i right that it uses a flat tx fee of 0.02851200 … if that is the max fee, i could just use that. Is that a viable approach for my grin coin gaming project?