Calculating mosaic fee

I’m trying to calculate mosaic fees of mosaic transfer in javascript. I was following https://nemproject.github.io/#transaction-fees And this is what I came up with:

function calculateFee(message, mosaicQuantity){
    let initialSupply = 100000000 // initial amount of mosaic, hundred millions(testing mosaic)
    let mosaicDivisibility = 6 // (for testig mosaic)
    let totalQuantity = initialSupply * Math.pow(10,mosaicDivisibility);
    let messageFee = ((message.length / 32 + 1) * 0.05)// message fee
    let adjustment = Math.floor(0.8 * Math.log(9000000000000000 / totalQuantity))
    let xemfee= Math.min(25,mosaicQuantity*900000/initialSupply)
    ....
    return messageFee + xemFee
}

How is xemFee calculated, there is no explanation for that only final calculation. 149,999 = 14XEM

You should look at nanowallet code (main.js):
https://github.com/NemProject/NanoWallet/releases/download/2.2.0/NanoWallet-2.2.0.zip

calculateMessage (line 184932) - for message fee calculation
calculateMosaics (line 184948) - for mosaic fee calculation
calculateMinimum (line 184989) - for minimum fee for transfer nem:xem

_construct (line 194117) - to see how fees are added.

1 Like