Running JavaScript code by Terminal: “Uncaught Reference Error: callback is not defined”


Running JavaScript code by Terminal: “Uncaught Reference Error: callback is not defined”



I want to get the output of following JavaScript code (i.e. a signed message) by Terminal (cmd).


Terminal


cmd




function constructPaymentMessage(contractAddress, amount) {
return ethereumjs.ABI.soliditySHA3(
["address", "uint256"],
[contractAddress, amount],
);
}

function signMessage(message, callback) {
web3.personal.sign("0x" + message.toString("hex"), web3.eth.defaultAccount,
callback);
}

// contractAddress is used to prevent cross-contract replay attacks.
// amount, in wei, specifies how much ether should be sent.
function signPayment(contractAddress, amount, callback) {
var message = constructPaymentMessage(contractAddress, amount);
signMessage(message, callback);
}

signPayment('0xca35b7d915458ef540ade6068dfe2f44e8fa733c', 1, callback);



I have already installed ethereumjs-abi that is needed for this code.
So, I have saved this code in a example.js file, however, it seems that I need to add invoking signPayment function in this file.
For example:


ethereumjs-abi


signPayment


signPayment('0xca35b7d915458ef540ade6068dfe2f44e8fa733c', 1, callback);



However, I am not sure about this approach of running .js file by Terminal. And I do not know eventually how to run this file to see its output (i.e. a signed message.)
Meanwhile, apparently signPayment does not return any value as output.


js


Terminal


signPayment


return


output



Here is the message that i receive:


root@ubuntu:/home/s# node sign.js
/home/s/sign.js:20
signPayment('0xca35b7d915458ef540ade6068dfe2f44e8fa733c', 1, callback);
^

ReferenceError: callback is not defined
at Object.<anonymous> (/home/s/sign.js:20:62)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)



How to get the out put of this JavaScript code ?



Note: I saved the JavaScript code in a .js file (You can see the content of this .js file HERE.) However, when I run this file by node filename.js I receive the error message that I uploaded the screen shot HERE. I do not know where I am going wrong.


JavaScript


.js


node filename.js









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages