QuantumMechanics / NEM-sdk

NEM Developer Kit for Node.js and the browser
MIT License
137 stars 82 forks source link

Apostille Multisig Transaction #52

Closed Maveth0 closed 6 years ago

Maveth0 commented 6 years ago

I'm making a simple apostille transaction based on the examples. It works fine when I'm not using a multisig account. But I don't know why it won't work as a multisig transaction.

Code:

var endpoint = nem.model.objects.create('endpoint')('http://bigalice2.nem.ninja', nem.model.nodes.defaultPort);

var common = nem.model.objects.create("common")("", "PrivateKey-Sender");

let fileContent = nem.crypto.js.enc.Utf8.parse('CONTRACT');

let apostille = nem.model.apostille.create(common, "Test.txt", fileContent, "Test Apostille", nem.model.apostille.hashing["SHA256"], true, "MultisigAddress", true, nem.model.network.data.testnet.id);

var d = new Date(),
    month = '' + (d.getMonth() + 1),
    day = '' + d.getDate(),
    year = d.getFullYear();

if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;

var date = [year, month, day].join('-');

var prepareContract = nem.model.transactions.prepare("signatureTransaction")(common, apostille, nem.model.network.data.testnet.id);

nem.model.transactions.send(common, prepareContract, endpoint).then(function(res){

// If code >= 2, it's an error
if (res.code >= 2) {
    console.error(res.message);
} else {
    console.log("\nTransaction: " + res.message);
    console.log("\nCreate a file with the fileContent text and name it:\n" + apostille.data.file.name.replace(/\.[^/.]+$/, "") + " -- Apostille TX " + res.transactionHash.data + " -- Date "+ date + "." + apostille.data.file.name.split('.').pop());
    console.log("When transaction is confirmed the file should audit successfully in Nano");
    console.log("\nYou can also take the following hash: " + res.transactionHash.data + " and put it into the audit.js example");
}
    }, function(err) {
    console.log(err);
    });
}

Error:

SCRIPT5007: Unable to get property 'data' of undefined or null reference nem-sdk.js (10126,9)

which points to:

// Signature transaction } else if (d[0] === _transactionTypes2.default.multisigSignature) { var temp = _convert2.default.hex2ua(entity['otherHash']['data']); ---- this line.

I've also tried removing the prepareContract then changing the send function as:

nem.model.transactions.send(common, apostille.transaction, endpoint).....

Error:

HTTP500: SERVER ERROR - The server encountered an unexpected condition that prevented it from fulfilling the request. (Fetch)POST - http://bigalice2.nem.ninja:7890/transaction/announce

Changing the endpoint doesn't make any difference.

Any help would be appreciated.

evias commented 6 years ago
var prepareContract = nem.model.transactions.prepare("signatureTransaction")(common, apostille, nem.model.network.data.testnet.id);

Shouldn't you use apostille.transaction here ? so replace with :

var prepareContract = nem.model.transactions.prepare("signatureTransaction")(common, apostille.transaction, nem.model.network.data.testnet.id);
Maveth0 commented 6 years ago

It still gives the same error as the first one which is:

SCRIPT5007: Unable to get property 'data' of undefined or null reference nem-sdk.js (10126,9)

Maveth0 commented 6 years ago

Figured it out. "MultisigAddress" should be the public key, not address. It wasn't really clear in the documentations.