I'm attempting to sign a contract transaction offline using web3js v1.2.11.
signingAddr = //my eth address
signingPk = //my private key
// docs: The options object for the contract instance. from, gas and gasPrice are used as fallback values when sending transactions.
myContractInstance.options = {
gas : 800000,
gasPrice : 60000000000,
value : 1000000000000000,
from : signingAddr
}
//docs: Creates a transaction object for that method, which then can be called, send, estimated.
let tx = await myContractInstance.methods.myFunction(myParam1,myParam2)
//docs: "Signs an Ethereum transaction with a given private key."
let signedTx = await web3.eth.signTransaction(tx,signingPk)
console.log(signedtx)
//Error: The send transactions "from" field must be defined!
I've also tried with:
let tx = await myContractInstance.methods.myFunction(myParam1,myParam2).send({from:signingAddr})
//TypeError: Cannot read property 'filter' of undefined
Links to docs:
I get that the tx object returned by the contract method is different to the tx object required for signTransaction. I'm unsure as to whether this is possible with web3.js?
It seems in earlier versions of web3js there was a getData function to get the needed call data.
How can I create valid signed contract call transactions offline using webjs v1.2.11?