首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用部署-zksync尝试部署智能契约时出错

使用部署-zksync尝试部署智能契约时出错
EN

Ethereum用户
提问于 2023-02-14 05:22:36
回答 1查看 922关注 0票数 0

在运行yarn hardhat deploy-zksync后,我得到了以下错误:

代码语言:javascript
复制
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.

deploy.ts脚本的代码如下:

代码语言:javascript
复制
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("");

  // 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}`);
}
EN

回答 1

Ethereum用户

回答已采纳

发布于 2023-02-14 11:48:35

该错误通常会返回,因为您试图部署的字节码对zkSync无效。您是否安装并配置了hardhat-zksync-solc插件,并使用它编译了契约?见这里的文件

检查您是否有一个artifacts-zk文件夹(这是在用zksolc编译后创建的),还检查您的契约JSON文件中生成的字节码(包含契约ABI的相同文件)是否为空。

我们发现了一些操作系统的问题,并发布了一个修复程序。确保您在hardhat.config.ts文件中使用zksolc版本的D4(或更高版本),并使用@matterlabs/hardhat-zksync-solc版本0.3.15 (或更高版本)。

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/144877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档