Try this (using web3.js v1):
let Web3 = require("web3");
let web3 = new Web3(NODE_ADDRESS);
async function send(transaction, reestimate = function(gas) {return gas;}) {
let gas = await transaction.estimateGas({from: PUBLIC_KEY});
let options = {
to : transaction._parent._address,
data: transaction.encodeABI(),
gas : reestimate(gas)
};
let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
}
Usage example #1:
let receipt = await send(myContract.methods.myFunc(arg1, arg2, arg3));
...
Usage example #2:
let reestimate = function(gas) {return gas * 2;};
let receipt = await send(myContract.methods.myFunc(arg1, arg2, arg3), reestimate);
...
web3.js
?It should sign the transaction on its own
- the API or the contract? (I don't see how the contract could possibly do that, but you just wrote it in a comment above).