I've written code to deploy contracts programatically. However when I set the same settings as remix ("gas price, gas limit, etc). The transaction mines but I get the error:
Warning! Error encountered during contract execution [out of gas]
Now, If I set the gasLimit to like 6m as opposed to the 3M gas suggested by Remix, The contract deploys successfully but at roughly 70% more of the fees than deploying on Remix.
Here's the code I'm using for the contract:
const input = {
language: "Solidity",
sources: {
"TestContract.sol": {
content: sourceCode,
},
},
settings: {
outputSelection: { "*": { "*": ["*"] } },
},
};
solc.loadRemoteVersion(compilerVersion, async (err, solcSnapshot) => {
if (err) {
console.log("inside error: ");
console.log("error compiling with solc: ", e);
} else {
const { contracts } = JSON.parse(
solcSnapshot.compile(JSON.stringify(input))
);
const contract = contracts["TestContract.sol"][<name of contract>];
const { abi } = contract;
const bytecode = contract.evm.bytecode.object;
const { signer, provider } = getSigner({ pk });
const factory = new ethers.ContractFactory(abi, bytecode, signer);
const deployContract = await factory.deploy();
const receipt = await deployContract.deployTransaction.wait();
}
})
I feel like maybe it has to do with the bytecode, but I'm not sure why that would differ from the same exact contract being compiled in Remix (Code is exactly the same).