I need to sign data using the private key and not keystore file. I can get data using:
var hash = "0x" + ethereumjs.ABI.soliditySHA3(
["address", "uint256", "uint256"],
[web3.eth.defaultAccount, amount, nonce]
).toString("hex");
and sign the data using:
web3.personal.sign(hash, web3.eth.defaultAccount, callback);
But I am not sure how can sign this message using private key and without use of unlocking the account.
I am not willing not use personal
over RPC calls.
Best Answer
Try these three functions:
All of which rely on this function:
Note that in web3.js v1.0.0-beta.34 or earlier (and possibly later as well), function
web3.eth.accounts.signTransaction
may change the values in theoptions
object passed to it.They've fixed it at some point (via deep-cloning of this object), but I'm not sure which version.
Therefore, we initialize a new
options
object at every iteration.In addition, since the latest block's gas-limit may change, we fetch it too at every iteration.