I keep getting the cannot estimate gas error when attempting to deploy a contract using solidity-create2-deployer package.
I am using the dai contract for testing purposes. I collect all the required parameters and follow the github instructions (https://github.com/thegostep/solidity-create2-deployer) however I cannot seem to get it right. I have also looked online without luck thus far. If anyone could assist Iโd be very grateful.
const creat2 = async () =>{
var daiAddress = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
const sourceCode = await fetch(`https://api.etherscan.io/api?module=contract&action=getsourcecode&address=${daiAddress}&apikey=${apiKey}`)
const getAbi = await fetch(`https://api.etherscan.io/api?module=contract&action=getAbi&address=${daiAddress}&apikey=${apiKey}`)
const jsonAbi = await getAbi?.json()
const abi = await jsonAbi?.result
var abijson = JSON.parse(abi)
console.log(abijson)
const saucy = await sourceCode?.json()
var source = await saucy?.result
var constructr = abijson.filter(object => object.type == "constructor")
var constructor = constructr[0]?.inputs
console.log(constructor)
if(source[0]?.Proxy == "1"){
var daiAddress = source[0]?.Implementation
const sourceCode = await fetch(`https://api.etherscan.io/api?module=contract&action=getsourcecode&address=${daiAddress}&apikey=${apiKey}`)
const saucy = await sourceCode?.json()
var source = await saucy?.result
console.log(source[0])
console.log(source[0]?.ConstructorArguments)
const getAbi = await fetch(`https://api.etherscan.io/api?module=contract&action=getAbi&address=${daiAddress}&apikey=${apiKey}`)
const jsonAbi = await getAbi?.json()
const abi = await jsonAbi?.result
var abijson = JSON.parse(abi)
var constructr = abijson.filter(object => object.type == "constructor")
var constructor = constructr[0]?.inputs
console.log(constructor)
// const constructor = ethers.utils.AbiCoder.prototype.decode(source[0]?.ConstructorArguments)
// console.log(constructor)
// decode args
}
let constructorTypes = []
for (let i =0; i<constructor.length; i++){
constructorTypes.push(constructor[i]?.internalType)
}
console.log(constructorTypes)
console.log(source[0]?.ConstructorArguments)
const bytecode = await web3.eth.getCode(daiAddress)
console.log(bytecode)
const salt = generateRandomSalt(); // Choose a salt value
// const constructorTypes = ["uint256"]
const constructorArgue = "0x" + source[0]?.ConstructorArguments
console.log(constructorArgue)
const constructorArgs = (ethers.utils.AbiCoder.prototype.decode(constructorTypes, constructorArgue)).toString()
console.log(constructorArgs)
const signer = new ethers.Wallet(initiatorPK, provider1); // Create a wallet with your private key and provider
const zaiAddress = getCreate2Address({
salt: salt,
contractBytecode: bytecode,
constructorTypes: constructorTypes,
constructorArgs: [constructorArgs]
});
console.log(zaiAddress)
const { txHash, address, receipt } = await deployContract({
salt: salt,
contractBytecode: bytecode,
constructorTypes: constructorTypes,
constructorArgs: [constructorArgs],
signer: signer,
});
const deployed = await isDeployed(address, provider1);
console.log(deployed)
}```