Error using js to create transaction

Hello,

I tried to create a transaction using code according to documentation in
https://nemlibrary.com/documentation/transaction/

My code is:

var myconst = require("./const.js"); // my account keys and address
var nem = require(“nem-library”);
nem.NEMLibrary.bootstrap(nem.NetworkTypes.TEST_NET);

const transferTransaction = nem.TransferTransaction.create(
nem.TimeWindow.createWithDeadline(),
new nem.Address(myconst.TEscoAddr),
new nem.XEM(2),
“testing js”
);

const privateKey = myconst.TNemTestPrivKey;

const account = Account.createWithPrivateKey(privateKey);

const transactionHttp = new TransactionHttp();
const signedTransaction = account.signTransaction(transferTransaction);

transactionHttp.announceTransaction(signedTransaction).subscribe( x => console.log(x));


However I get the error

C:\Users\micro\OneDrive\Coding\NEM\node_modules\nem-library\dist\src\models\tran
saction\TransferTransaction.js:122
if (message.payload.length != 0) {
^

TypeError: Cannot read property ‘length’ of undefined
at Function.create (C:\Users\micro\OneDrive\Coding\NEM\node_modules\nem-libr
ary\dist\src\models\transaction\TransferTransaction.js:122:29)
at Object. (C:\Users\micro\OneDrive\Coding\NEM\index.js:46:53)
at Module._compile (module.js:652:30)
at Object.Module._extensions…js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3

As far as I can see message should be of type PlainMessage or EncryptedMessage, not String.

Hello pawelm,
I see the error. Corrected and works. Thank you.

1 Like