NEM-sdk: Error? in prepare("mosaicTransferTransaction") result fee is null.

Hi, I am always indebted to NEM-sdk.

I noticed that the result of calling nem.model.transactions.prepare (“mosaicTransferTransaction”) is Fee null.

var transactionEntity = nem.model.transactions.prepare("mosaicTransferTransaction")(common, transferTransaction, mosaicDefinitionMetaDataPair, nem.model.network.data.testnet.id);
// !transactionEntity.fee == null;

Moreover, I think that cause is in the following code of the calculateMosaics function. In the following code, is not it possible to get initialSupply correctly? fees.js#124

        let supply = mosaicDefinitionMetaDataPair.supply; //

I can get initialSupply if I change it like this, fee will not be undefine.

        let initialSupplyProperties = Helpers.grep(mosaicDefinitionMetaDataPair.mosaicDefinition.properties, function(w) {
            return w.name === "initialSupply";
        });
        let supply = initialSupplyProperties.length === 1 ? (initialSupplyProperties[0].value) : 0;

I will separately send you a pull request, please check. thank, you.

*Also, I am bad at English. I am using Google Translate to write this issue.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 5
  • Comments: 19 (4 by maintainers)

Most upvoted comments

no it doesnt cost you 1 XEM, in case of mosaic transfers, the transaction.amount field is used as a multiplier for the attachments. You only pay the fee + the mosaics attached (in case transaction.amount is not 0)

This means if you put 3 there, it would affect the balance 3 times with said attachments.

For noobs it would be nice to fix the example code provided with the one liner:

mosaicDefinitionMetaDataPair[fullMosaicName].supply = neededDefinition[fullMosaicName].properties[1].value;

around this line: https://github.com/QuantumMechanics/NEM-sdk/blob/master/examples/nodejs/mosaicTransfer.js#L57

Until discovering this thread on github, I verified I could set the fee manually and get a successful transaction. However, glad to find a solution on the forums.

@maxp Thanks for giving me a hint! I rewrote the example.

// Include the library
var nem = require("../../build/index.js").default;

~~~~~~~~
nem.com.requests.namespace.mosaicDefinitions(endpoint, mosaicAttachment2.mosaicId.namespaceId).then(function(res) {

        // Look for the mosaic definition(s) we want in the request response (Could use ["eur", "usd"] to return eur and usd mosaicDefinitionMetaDataPairs)
        var neededDefinition = nem.utils.helpers.searchMosaicDefinitionArray(res.data, ["eur"]);

        // Get full name of mosaic to use as object key
        var fullMosaicName  = nem.utils.format.mosaicIdToName(mosaicAttachment2.mosaicId);

        // Check if the mosaic was found
        if(undefined === neededDefinition[fullMosaicName]) return console.error("Mosaic not found !");

        // Set eur mosaic definition into mosaicDefinitionMetaDataPair
        mosaicDefinitionMetaDataPair[fullMosaicName] = {};
        mosaicDefinitionMetaDataPair[fullMosaicName].mosaicDefinition = neededDefinition[fullMosaicName];

        // ★Get current supply with nem:xem
        nem.com.requests.mosaic.supply(endpoint, nem.utils.format.mosaicIdToName(mosaicAttachment.mosaicId)).then(function(res) {
                mosaicDefinitionMetaDataPair[nem.utils.format.mosaicIdToName(mosaicAttachment.mosaicId)].supply = res.supply;
                // ★Get current supply with eur:usd
                nem.com.requests.mosaic.supply(endpoint, fullMosaicName).then(function(res) {
                        mosaicDefinitionMetaDataPair[fullMosaicName].supply = res.supply;
                        // Prepare the transfer transaction object
                        var transactionEntity = nem.model.transactions.prepare("mosaicTransferTransaction")(common, transferTransaction, mosaicDefinitionMetaDataPair, nem.model.network.data.testnet.id);

                        // Serialize transfer transaction and announce
                        nem.model.transactions.send(common, transactionEntity, endpoint);
                }, function(err) {
                console.error(err);
                });
        }, function(err) {
        console.error(err);
        });

}, function(err) {
    console.error(err);
});

@QuantumMechanics Thank you for giving me a reply! Please let me question as many as 2 points.

  1. “nem.com.requests.mosaic.supply()” is not listed in the README but can I use it?
  2. nem-library-ts uses initialSupply. Is this a mistake? https://github.com/aleixmorgadas/nem-library-ts/blob/d8df40c5a1f8b2cc858e416d7c0f9801d21e6d2d/src/models/transaction/TransferTransaction.ts#L209 I do not think it is directly related, but I’d like to ask your opinion.

Confirm the bug.

Can confirm that this error blocks mosaic transfers and that the proposed fix fixes the issue. Thanks, @scrpgil !