1

I am getting the following error after running yarn hardhat deploy-zksync:

Running deploy script for the Greeter contract
An unexpected error occurred:

Error: Bytecode length in 32-byte words must be odd
    at hashBytecode (/Users/matifalcone/GMG/P2E/smart-contracts-sponsored-transactions/node_modules/zksync-web3/build/src/utils.js:205:15)
    at ContractFactory.getDeployTransaction (/Users/matifalcone/GMG/P2E/smart-contracts-sponsored-transactions/node_modules/zksync-web3/build/src/contract.js:42:55)
    at Deployer.estimateDeployGas (/Users/matifalcone/GMG/P2E/smart-contracts-sponsored-transactions/node_modules/@matterlabs/hardhat-zksync-deploy/src/deployer.ts:157:34)
    at async Deployer.estimateDeployFee (/Users/matifalcone/GMG/P2E/smart-contracts-sponsored-transactions/node_modules/@matterlabs/hardhat-zksync-deploy/src/deployer.ts:139:21)
    at async default_1 (/Users/matifalcone/GMG/P2E/smart-contracts-sponsored-transactions/deploy/deploy.ts:20:25)
    at async runScript (/Users/matifalcone/GMG/P2E/smart-contracts-sponsored-transactions/node_modules/@matterlabs/hardhat-zksync-deploy/src/plugin.ts:73:5)
    at async callDeployScripts (/Users/matifalcone/GMG/P2E/smart-contracts-sponsored-transactions/node_modules/@matterlabs/hardhat-zksync-deploy/src/plugin.ts:43:13)
    at async SimpleTaskDefinition.zkSyncDeploy [as action] (/Users/matifalcone/GMG/P2E/smart-contracts-sponsored-transactions/node_modules/@matterlabs/hardhat-zksync-deploy/src/task-actions.ts:5:5)
    at async Environment._runTaskDefinition (/Users/matifalcone/GMG/P2E/smart-contracts-sponsored-transactions/node_modules/hardhat/src/internal/core/runtime-environment.ts:311:14)
    at async Environment.run (/Users/matifalcone/GMG/P2E/smart-contracts-sponsored-transactions/node_modules/hardhat/src/internal/core/runtime-environment.ts:159:14)
error Command failed with exit code 1.

The code for the deploy.ts script is as follows:

import { Wallet, utils } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

// An example of a deploy script that will deploy and call a simple contract.
export default async function (hre: HardhatRuntimeEnvironment) {
  console.log(`Running deploy script for the Greeter contract`);

  // Initialize the wallet.
  const wallet = new Wallet("<WALLET-PRIVATE-KEY>");

  // Create deployer object and load the artifact of the contract you want to deploy.
  const deployer = new Deployer(hre, wallet);
  const artifact = await deployer.loadArtifact("Greeter");

  // Estimate contract deployment fee
  const greeting = "Hi there!";
  const deploymentFee = await deployer.estimateDeployFee(artifact, [greeting]);

  // Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
  // `greeting` is an argument for contract constructor.
  const parsedFee = ethers.utils.formatEther(deploymentFee.toString());
  console.log(`The deployment is estimated to cost ${parsedFee} ETH`);

  const greeterContract = await deployer.deploy(artifact, [greeting]);

  //obtain the Constructor Arguments
  console.log("constructor args:" + greeterContract.interface.encodeDeploy([greeting]));

  // Show the contract info.
  const contractAddress = greeterContract.address;
  console.log(`${artifact.contractName} was deployed to ${contractAddress}`);
}

1 Answer 1

1

That error is normally return because the bytecode you're trying to deploy is not valid for zkSync. Have you installed and configured the hardhat-zksync-solc plugin, and compiled the contracts with it? See the documentation here

Check if you have an artifacts-zk folder (this is created after compiling with zksolc) and also check if the generated bytecode in your contract JSON file (the same file that has the contract ABI) is not empty.

We identified an issue with some operating systems and released a fix. Make sure you're using zksolc version 1.3.8 (or higher) in your hardhat.config.ts file and use @matterlabs/hardhat-zksync-solc version 0.3.15 (or higher).

5
  • Thanks for your answer. I am effectively compiling with zksolc BUT I do see the bytecode as 0x. This is my hardhat.config.ts: gist.github.com/matias-gmg/78801e79d864afe73bebdd2c4d6b2117 Commented Feb 15, 2023 at 1:00
  • Sorry for the late reply. Can you share your Node.js/NPM, and your OS versions? We're trying to figure out what's causing this issue
    – Antonio U
    Commented Feb 23, 2023 at 19:36
  • Node v18.14.0 / NPM v9.3.1 / macOS Ventura Version 13.2.1 (22D68) Commented Feb 24, 2023 at 0:13
  • Marking this question as answered as effectively that's the problem I am having (the bytecode is being compiled as 0x using zksolc). Anyway, I am tracking in another question the why of this. Commented Apr 6, 2023 at 3:00
  • we've released a fix for this specific issue. Make sure you're using zksolc version 1.3.8 in your hardhat.config.ts file and @matterlabs/hardhat-zksync-solc version 0.3.15
    – Antonio U
    Commented Apr 7, 2023 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.