[Deployment] ERC1167 create failed error when cloning a contract #605
-
EnvironmentTestnet zkSolc Versionv1.4.1 zksync-ethers Version1.0.0 Hardhat.config.tsimport { HardhatUserConfig } from "hardhat/config";
import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-verify";
import "@matterlabs/hardhat-zksync-node";
const config: HardhatUserConfig = {
defaultNetwork: "zkSyncSepoliaTestnet",
networks: {
zkSyncSepoliaTestnet: {
url: "https://sepolia.era.zksync.dev",
ethNetwork: "sepolia",
zksync: true,
verifyURL: "https://explorer.sepolia.era.zksync.dev/contract_verification"
},
zkSyncMainnet: {
url: "https://mainnet.era.zksync.io",
ethNetwork: "mainnet",
zksync: true,
verifyURL:
"https://zksync2-mainnet-explorer.zksync.io/contract_verification"
},
zkSyncGoerliTestnet: {
// deprecated network
url: "https://testnet.era.zksync.dev",
ethNetwork: "goerli",
zksync: true,
verifyURL:
"https://zksync2-testnet-explorer.zksync.dev/contract_verification"
},
dockerizedNode: {
url: "http://localhost:3050",
ethNetwork: "http://localhost:8545",
zksync: true
},
inMemoryNode: {
url: "http://127.0.0.1:8011",
ethNetwork: "localhost", // in-memory node doesn't support eth node; removing this line will cause an error
zksync: true
},
hardhat: {
zksync: true
}
},
zksolc: {
version: "1.4.1",
settings: {
// find all available options in the official documentation
// https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html#configuration
}
},
solidity: {
version: "0.8.21"
}
};
export default config; Deployment Script (WITHOUT PRIVATE KEY)import { ethers } from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Provider } from "zksync-ethers";
import * as ContractArtifact from "../artifacts-zk/contracts/sale/v2.1/FlatPriceSaleFactory.sol/FlatPriceSaleFactory_v_2_1.json";
// load env file
import dotenv from "dotenv";
dotenv.config();
const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "";
export default async function (hre: HardhatRuntimeEnvironment) {
// original
// flatPriceSaleFactory_v_2_1Address: 0xC96D8047B0B812c10e798cB249402a15c5c0753F
// cloneDeterministic/create2 alternative
// flatPriceSaleFactory_v_2_1Address: 0xb0280B6d67fA691a479f94FC49B97f4020110C08
const flatPriceSaleFactory_v_2_1Address =
"0xC96D8047B0B812c10e798cB249402a15c5c0753F";
const provider = new Provider(
// @ts-ignore
hre.userConfig.networks?.zkSyncSepoliaTestnet?.url
);
const signer = new ethers.Wallet(PRIVATE_KEY, provider);
const contract = new ethers.Contract(
flatPriceSaleFactory_v_2_1Address,
ContractArtifact.abi,
signer
);
// Define example parameters for the `newSale` function
const owner = "0xb4B95fC47Bb797AcC777e5A2AA27c23C294637eE"; // Owner address
const config = {
recipient: "0xb4B95fC47Bb797AcC777e5A2AA27c23C294637eE", // Address of the recipient
merkleRoot:
"0xd8f40d4066981cc19d5b89c9772581b63409b1a1ce863c1103396cd57587ee81", // Merkle root as bytes32
saleMaximum: "2000000000", // Maximum sale amount
userMaximum: "2000000000", // Maximum per user
purchaseMinimum: "1000000000", // Minimum purchase amount
startTime: 1718909040, // Start time in UNIX timestamp
endTime: 1719513840, // End time in UNIX timestamp
maxQueueTime: 0, // Maximum queue time in seconds
URI: "ipfs://QmXsPfyn9Hp41LsCpHMg44ecynS8LcvEPPF9xD7EsNKSrv" // Metadata URI
};
const baseCurrency = "USD";
const nativePaymentsEnabled = true;
const nativeTokenPriceOracle = "0x6D41d1dc818112880b40e26BD6FD347E41008eDA";
const tokens = [];
const oracles = [];
const decimals = [];
// Call `newSale` function on contract
console.log(
`The message is ${await contract.newSale(
owner,
config,
baseCurrency,
nativePaymentsEnabled,
nativeTokenPriceOracle,
tokens,
oracles,
decimals
)}`
);
console.log("✅ Deployment complete!");
} Package.json{
"name": "hello-zksync-quickstart",
"description": "A template for zkSync smart contracts development with Hardhat",
"private": true,
"author": "Matter Labs",
"license": "MIT",
"repository": "https://github.com/matter-labs/zksync-hardhat-template.git",
"scripts": {
"deploy": "hardhat deploy-zksync --script deploy.ts",
"compile": "hardhat compile",
"clean": "hardhat clean"
},
"devDependencies": {
"@matterlabs/hardhat-zksync": "^1.0.0",
"@matterlabs/zksync-contracts": "^0.6.1",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.6",
"@openzeppelin/contracts": "^4.6.0",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"chai": "^4.3.7",
"dotenv": "^16.0.3",
"ethers": "^6.9.2",
"hardhat": "^2.12.4",
"mocha": "^10.2.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"zksync-ethers": "^6.7.0"
},
"dependencies": {
"@chainlink/contracts": "^0.6.1",
"@openzeppelin/contracts-upgradeable": "4.6.0"
}
} Contract Code// SPDX-License-Identifier: MIT
pragma solidity =0.8.21;
import "@openzeppelin/contracts/proxy/Clones.sol";
import "./FlatPriceSale.sol";
contract FlatPriceSaleFactory_v_2_1 {
address public immutable implementation;
string public constant VERSION = "2.0";
event NewSale(
address indexed implementation,
FlatPriceSale_v_2_1 indexed clone,
Config config,
string baseCurrency,
IOracleOrL2OracleWithSequencerCheck nativeOracle,
bool nativePaymentsEnabled
);
constructor(address _implementation) {
implementation = _implementation;
}
function newSale(
address _owner,
Config calldata _config,
string calldata _baseCurrency,
bool _nativePaymentsEnabled,
IOracleOrL2OracleWithSequencerCheck _nativeTokenPriceOracle,
IERC20Upgradeable[] calldata tokens,
IOracleOrL2OracleWithSequencerCheck[] calldata oracles,
uint8[] calldata decimals
) external returns (FlatPriceSale_v_2_1 sale) {
// cloneDeterministic/create2 alternative
// sale = FlatPriceSale_v_2_1(Clones.cloneDeterministic(address(implementation), keccak256(abi.encodePacked(_owner, _baseCurrency, _nativePaymentsEnabled, _nativeTokenPriceOracle, tokens, oracles, decimals))));
sale = FlatPriceSale_v_2_1(Clones.clone(address(implementation)));
emit NewSale(
implementation,
sale,
_config,
_baseCurrency,
_nativeTokenPriceOracle,
_nativePaymentsEnabled
);
sale.initialize(
_owner,
_config,
_baseCurrency,
_nativePaymentsEnabled,
_nativeTokenPriceOracle,
tokens,
oracles,
decimals
);
}
} Does this work on other EVMs? (If yes, please list at least 1 of them)Ethereum, Base, and others. Description of What Your Contract DoesOnce you call the function Repo Link (Optional)https://github.com/ArshaanB/contract-factory-quickstart Additional DetailsAfter reading quite a few discussion posts on this topic and the page on zkSync about CREATE/CREATE2 (https://docs.zksync.io/build/developer-reference/ethereum-differences/evm-instructions#create-create2) I'm left confused as to how I can fix this error or work around it. Would appreciate any guidance here. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Thanks for posting. Will look this over and see what's up |
Beta Was this translation helpful? Give feedback.
hey @ArshaanB, erc1167 isn't supported on zksync due to the different bytecode format. Instead, can you try a proxy, something like this: