Formula to calculate mosaic transfer fees and min/max transaction fees

Good day Nem Forum!

I’m creating a nem wallet app on nodejs using the nem sdk (https://github.com/QuantumMechanics/NEM-sdk)

I’ve got 2 questions on mosaic transfer fees. I’ve followed the instructions on the documentation (https://nemproject.github.io/#transaction-fees) on how to calculate transaction fees. Regarding NON small business mosaics I’ve followed the calculations given, and verified that it works by replicating the example given.

My first question is, when calculating transaction fees using the calculation for a mosaic that has 9,000,000,000 supply, a divisibility of 6, and sending 1 mosaic will result in a fee of 4.95XEM. Is this unusually large?

Which leads me to my second question, about minimum and maximum fees. Do transaction fees have a minimum and maximum fee like message fees that have a min of 0.05XEM and a max of 1.25XEM? Based on this code from Dmatafonov (https://github.com/Dmatafonov/nem-php/blob/master/nem-php.php), if I’m not mistaken, he is implementing this min and max on transaction fees.

Would appreciate any help,
Thank you very much.

2 Likes

hello,
could you tell how you calculated 4.95 ?

UPDATE

I’ve done more reading and I can now answer my second question. There is a 0.05 minimum and 1.25 maximum since fees are in XEM item 1 of https://nemproject.github.io/#transaction-fees will apply.

Fees for transferring XEM to another account:
0.05 XEM per 10,000 XEM transferred, capped at 1.25 XEM
Example:
0.20 XEM fee for a 45,000 XEM transfer, 1.25 XEM fee for a 500,000 XEM transfer.

This is from the example given in (https://nemproject.github.io/#transaction-fees) which outputs the same 0.15 fee
Supply: 9000000
Divisibility: 3
Amount: 150

totalMosaicQuantity:
supply * Math.pow(10,divisibility) = totalMosaicQuantity
9000000 * Math.pow(10,3) = 9000000000

supplyRelatedAdjustment:
Math.floor(0.8 * Math.log( maxMosaicQuantity / totalMosaicQuantity ) = supplyRelatedAdjustment
Math.floor(0.8 * Math.log(9000000000000000 / 9000000000) = 11

xemEquivalent:
8999999999 * mosaicSmallestUnits / supply * Math.pow(10,divisibility)) = xemEquivalent
8999999999 * 150000 / 9000000 * Math.pow(10,3)) = 149999999983.3333

xemFee:
Math.floor(xemEquivalent / (10000 * 1000000)) = xemFee
Math.floor(149999999983.3333 / (10000 * 1000000)) = 14

unweightedFee
xemFee - supplyRelatedAdjustment = unweightedFee
14-11 = 3

fee
(unweightedFee * feeUnit ).toFixed(2) = fee
(3*0.05).toFixed(2) = 0.15

I then calculate a different mosaic, which gives me a 4.95 fee
Supply: 9000000000
Divisibility: 6
Amount: 1

totalMosaicQuantity:
supply * Math.pow(10,divisibility) = totalMosaicQuantity
9000000000 * Math.pow(10,6) = 9000000000000000

supplyRelatedAdjustment:
Math.floor(0.8 * Math.log( maxMosaicQuantity / totalMosaicQuantity ) = supplyRelatedAdjustment
Math.floor(0.8 * Math.log(9000000000000000 / 9000000000000000) = 0

xemEquivalent:
8999999999 * mosaicSmallestUnits / supply * Math.pow(10,divisibility)) = xemEquivalent
8999999999 * 1000000 / 9000000000 * Math.pow(10,6)) = 999999999888.8889

xemFee:
Math.floor(xemEquivalent / (10000 * 1000000)) = xemFee
Math.floor(999999999888.8889 / (10000 * 1000000)) = 99

unweightedFee
xemFee - supplyRelatedAdjustment = unweightedFee
99-0 = 99
fee
(unweightedFee * feeUnit ).toFixed(2) = fee
(99*0.05).toFixed(2) = 4.95

The calculation of xemFee has a rule of up to 25.
Also, unweightedFee has a rule of at least 1.

These are not all written in the specification.
Moreover, it is further omitted in the part of Example.

It is better to look at the formula from NanoWallet source code.

Thanks.

2 Likes

Thanks will do.

1 Like

As xem value grows will it always be that fixed rate? This seems to be the problem with crypto, as xem grows in value these fees get insane as well.

Hi, what will the minimum transaction fee to store the data in the NEM? and how to calculate the transaction fee based on the data size.

Hi,
It’s described here:
https://nemproject.github.io/#transaction-fees

" 1. Fees for appending a message to a transaction:
0.05 XEM per commenced 32 message bytes (messageLength / 32 + 1).
Example:
The unencrypted message „The New Economy Movement will change the world!!!” has a length 49 characters and thus will cost 0.15 XEM fee."

0.05xem minimal fee + 0.1xem for message

You can include up to 1024bytes in one transaction.

Hi, thanks for the quick response. In my case, I do not need to transfer the XEM from one account to another. I simply want to store the data.

You can attach message to transaction.
You can transfer 0 xem and add message.

That’s great. Is there any other way to store data more than 1024 bytes. Can I use nem smart assets?

I don’t know your use case but if you want store pretty big amount of data then blockchain is not good solution because is not designed to it.