Unable to deploy the code to era Testnet using any of the tools (zk-forge/hardhat / forge) #218
-
EnvironmentTestnet Provide a brief description of the functionality you're trying to implement.I am trying to deploy an AMM-based code on the zk-sync testnet. But unable to do so. I used all the different tools but all seem to fail while deploying or compiling. The hardhat and forge can compile and deploy it to the Sepolia testnet, but on zk-sync it just fails. What is the specific issue or error you're encountering?The issue is that I am unable to understand which is the correct method to deploy it on the era testnet, Can you share the error messages or logs you're receiving, if any?While using zk-forge I get the following error:
`deploy/utils.ts import { Provider, Wallet } from "zksync-web3";
import * as hre from "hardhat";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import dotenv from "dotenv";
import { formatEther } from "ethers/lib/utils";
import { BigNumberish } from "ethers";
import "@matterlabs/hardhat-zksync-node/dist/type-extensions";
import "@matterlabs/hardhat-zksync-verify/dist/src/type-extensions";
// Load env file
dotenv.config();
export const getProvider = () => {
const rpcUrl = "https://testnet.era.zksync.dev";
if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`;
// Initialize zkSync Provider
const provider = new Provider(rpcUrl);
return provider;
}
export const getWallet = (privateKey?: string) => {
if (!privateKey) {
// Get wallet private key from .env file
if (!process.env.WALLET_PRIVATE_KEY) throw "⛔️ Wallet private key wasn't found in .env file!";
}
const provider = getProvider();
// Initialize zkSync Wallet
const wallet = new Wallet(privateKey ?? process.env.WALLET_PRIVATE_KEY!, provider);
return wallet;
}
export const verifyEnoughBalance = async (wallet: Wallet, amount: BigNumberish) => {
// Check if the wallet has enough balance
const balance = await wallet.getBalance();
if (balance.lt(amount)) throw `⛔️ Wallet balance is too low! Required ${formatEther(amount)} ETH, but current ${wallet.address} balance is ${formatEther(balance)} ETH`;
}
/**
* @param {string} data.contract The contract's path and name. E.g., "contracts/Greeter.sol:Greeter"
*/
export const verifyContract = async (data: {
address: string,
contract: string,
constructorArguments: string,
bytecode: string
}) => {
const verificationRequestId: number = await hre.run("verify:verify", {
...data,
noCompile: true,
});
return verificationRequestId;
}
type DeployContractOptions = {
/**
* If true, the deployment process will not print any logs
*/
silent?: boolean
/**
* If true, the contract will not be verified on Block Explorer
*/
noVerify?: boolean
/**
* If specified, the contract will be deployed using this wallet
*/
wallet?: Wallet
}
export const deployContract = async (contractArtifactName: string, constructorArguments?: any[], options?: DeployContractOptions) => {
const log = (message: string) => {
if (!options?.silent) console.log(message);
}
log(`\nStarting deployment process of "${contractArtifactName}"...`);
const wallet = options?.wallet ?? getWallet();
const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact(contractArtifactName).catch((error) => {
if (error?.message?.includes(`Artifact for contract "${contractArtifactName}" not found.`)) {
console.error(error.message);
throw `⛔️ Please make sure you have compiled your contracts or specified the correct contract name!`;
} else {
throw error;
}
});
// Estimate contract deployment fee
const deploymentFee = await deployer.estimateDeployFee(artifact, constructorArguments || []);
log(`Estimated deployment cost: ${formatEther(deploymentFee)} ETH`);
// Check if the wallet has enough balance
await verifyEnoughBalance(wallet, deploymentFee);
// Deploy the contract to zkSync
const contract = await deployer.deploy(artifact, constructorArguments);
const constructorArgs = contract.interface.encodeDeploy(constructorArguments);
const fullContractSource = `${artifact.sourceName}:${artifact.contractName}`;
// Display contract deployment info
log(`\n"${artifact.contractName}" was successfully deployed:`);
log(` - Contract address: ${contract.address}`);
log(` - Contract source: ${fullContractSource}`);
log(` - Encoded constructor arguments: ${constructorArgs}\n`);
if (!options?.noVerify && hre.network.config.verifyURL) {
log(`Requesting contract verification...`);
await verifyContract({
address: contract.address,
contract: fullContractSource,
constructorArguments: constructorArgs,
bytecode: artifact.bytecode,
});
}
return contract;
}
/**
* Rich wallets can be used for testing purposes.
* Available on zkSync In-memory node and Dockerized node.
*/
export const LOCAL_RICH_WALLETS = [
{
address: "0x36615Cf349d7F6344891B1e7CA7C72883F5dc049",
privateKey: "0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"
},
{
address: "0xa61464658AfeAf65CccaaFD3a512b69A83B77618",
privateKey: "0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3"
},
{
address: "0x0D43eB5B8a47bA8900d84AA36656c92024e9772e",
privateKey: "0xd293c684d884d56f8d6abd64fc76757d3664904e309a0645baf8522ab6366d9e"
},
{
address: "0xA13c10C0D5bd6f79041B9835c63f91de35A15883",
privateKey: "0x850683b40d4a740aa6e745f889a6fdc8327be76e122f5aba645a5b02d0248db8"
},
{
address: "0x8002cD98Cfb563492A6fB3E7C8243b7B9Ad4cc92",
privateKey: "0xf12e28c0eb1ef4ff90478f6805b68d63737b7f33abfa091601140805da450d93"
},
{
address: "0x4F9133D1d3F50011A6859807C837bdCB31Aaab13",
privateKey: "0xe667e57a9b8aaa6709e51ff7d093f1c5b73b63f9987e4ab4aa9a5c699e024ee8"
},
{
address: "0xbd29A1B981925B94eEc5c4F1125AF02a2Ec4d1cA",
privateKey: "0x28a574ab2de8a00364d5dd4b07c4f2f574ef7fcc2a86a197f65abaec836d1959"
},
{
address: "0xedB6F5B4aab3dD95C7806Af42881FF12BE7e9daa",
privateKey: "0x74d8b3a188f7260f67698eb44da07397a298df5427df681ef68c45b34b61f998"
},
{
address: "0xe706e60ab5Dc512C36A4646D719b889F398cbBcB",
privateKey: "0xbe79721778b48bcc679b78edac0ce48306a8578186ffcb9f2ee455ae6efeace1"
},
{
address: "0xE90E12261CCb0F3F7976Ae611A29e84a6A85f424",
privateKey: "0x3eb15da85647edd9a1159a4a13b9e7c56877c4eb33f614546d4db06a51868b1c"
}
] contracts/.../Sinkdrain.sol pragma solidity 0.8.19;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
/// @notice Fake pool used to create the gauge which directs all emissions of velo v1 to the SinkManager
/// @dev Used in voter v1
contract SinkDrain is ERC20, Ownable {
constructor() ERC20("SinkDrain", "DRAIN") {}
function mint(address _sinkManager) external onlyOwner {
// Mint to sinkManager so that it can provide all the liquidity
_mint(_sinkManager, 1e18);
renounceOwnership();
}
}
Have you tried to isolate the problem, and if so, what were the results?Unable to Isolate the issue. What steps have you already taken to try to resolve the issue?Trying different combinations of deployment scripts and tools. None has worked until now. Repo Link (Optional)No response Additional DetailsNo response |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 15 replies
-
Hey @rajrohit10 👋 I definitely recommend making use of hardhat at this time as our Foundry support is in development. A couple questions about your setup: |
Beta Was this translation helpful? Give feedback.
-
This is how my hardhat.config.ts looks. I use the nomic import to deploy to sepolia and the matterlabs import for zksync import * as dotenv from "dotenv";
import "@nomicfoundation/hardhat-toolbox";
import "@nomicfoundation/hardhat-foundry";
//For zksync
// "@matterlabs/hardhat-zksync-deploy";
// "@matterlabs/hardhat-zksync-solc";
dotenv.config();
export default {
defaultNetwork: "sepolia",
networks: {
hardhat: {
},
sepolia: {
url: `https://eth-sepolia.g.alchemy.com/v2/wJ4MOyRL_MQ9a3jJiFVpBGrfZf9jmVKL`,
accounts: [`${process.env.PRIVATE_KEY_DEPLOY}`]
},
zksync: {
url: `https://testnet.era.zksync.dev`,
ethNetwork: "goerli", // or a Goerli RPC endpoint from Infura/Alchemy/Chainstack etc.
zksync: true,
accounts: [`${process.env.PRIVATE_KEY_DEPLOY}`]
}
},
solidity: {
version: "0.8.19",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
tenderly: {
username: "vff",
project: "v2",
privateVerification: false
},
paths: {
sources: "./contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts"
},
typechain: {
outDir: "artifacts/types",
target: "ethers-v5"
}
}; Right now when i use forge to deploy the script to zksync I get the following error:
I used this script to deploy
Also the issue with hardhat is that I am able to compile and deploy it on sepolia. But once i try that with zksync, it gives the following error: Also I can compile and deploy on Sepolia using hardhat, But once I install Matterlabs plugins, I can't do that either on seplia |
Beta Was this translation helpful? Give feedback.
-
So I updated my hardhat config file with this:
and this is deploy script
While compiling using yarn hardhat compile :
|
Beta Was this translation helpful? Give feedback.
-
So I was playing with the code. Did some changes (not sure if that was the right approach) , but i was able to get here:
But again after trying to run the compile command, it gives the same issue. |
Beta Was this translation helpful? Give feedback.
-
So i deployed all the library contract.
So i manually added the contract addresses in the hardhat file. but after that compilation still isnt generating artifacts file.
|
Beta Was this translation helpful? Give feedback.
-
So I was able to create an artifacts-sk folder after successful compilation. But when i tried to deploy my script , I go the following error :
|
Beta Was this translation helpful? Give feedback.
-
Currently i am having the following issues:
And at zksolc 1.3.22 i get the following error :
i have found similar issues on this on the discussion but not a working solution |
Beta Was this translation helpful? Give feedback.
You can manually add addresses as you've mentioned you did. To circumvent the issue below and for a cleaner compilation:
Update your HH config from
export default {
toexport const config = {
. Be sure to add addexport default config;
to the bottom of the file. With a named configuration the plugin will automatically add the deployed libraries accordingly. So for your config: