Try this (using web3.js v1):
let fs = require("fs");
let Web3 = require("web3");
let web3 = new Web3(NODE_ADDRESS);
async function send(transaction) {
let gas = await transaction.estimateGas({from: ACCOUNT_ADDRESS});
let options = {
to : transaction._parent._address,
data: transaction.encodeABI(),
gas : gas
};
let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
}
async function deploy(contractName, contractArgs) {
let abi = fs.readFileSync(BINARY_DIR + contractName + ".abi").toString();
let bin = fs.readFileSync(BINARY_DIR + contractName + ".bin").toString();
let contract = new web3.eth.Contract(JSON.parse(abi));
let handle = await send(contract.deploy({data: "0x" + bin, arguments: contractArgs}));
console.log(`${contractName} contract deployed at address ${handle.contractAddress}`);
return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);
}
Usage example:
let myContract = await deploy("MyContract", [arg1, arg2, arg3]);
...