I'm using ethers' ContractFactory to deploy a contract with Alchemy RPCs.
async deployContract(contractObject: ContractObjectDto) {
try {
const chain = contractObject.chain.toLowerCase() as Chains;
const network = contractObject.network.toLowerCase() as Networks;
const Factory = new ethers.ContractFactory(
this.getContractInterface(contractObject.type).abi,
this.getContractInterface(contractObject.type).bytecode,
this.getSigner(chain, network),
);
const contract = await Factory.deploy(
contractObject.name,
contractObject.symbol,
);
await contract.deployed();
return contract.address;
} catch (error) {
throw error;
}
}
It works for Arbitrum Mainnet/Goerli, Optimism Mainnet/Goerli, and Polygon Mumbai. However, it fails for Polygon Mainnet. There, I get the error:
Error: processing response error (body="{\"jsonrpc\":\"2.0\",\"id\":47,\"error\":
{\"code\":-32000,\"message\":\"transaction underpriced\"}}",
error={"code":-32000}, requestBody="{\"method\":\"eth_sendRawTransaction\",\"params\":...
Even if I specify the gas, like below, I still get the error. I have also tried using an Infura RPC, but the result is the same.
const provider = getWeb3ProviderThroughEthers(chain, network);
const price = ethers.utils.formatUnits(
await provider.getGasPrice(),
'gwei',
);
contract = await Factory.deploy(
contractObject.name,
contractObject.symbol,
{
gasLimit: 100000,
gasPrice: ethers.utils.parseUnits(price, 'gwei'),
},
);