1

Below is a snippet of code I am using to compute the hashed bytecode of a contract, however this doesn't seem to work. This hash is passed to the create function of the zkSync Era ContractDeployer.sol system contract?

const contractDeployerAddress = "0x0000000000000000000000000000000000008006"
const contractDeployer = new ethers.Contract(contractDeployerAddress, abi.abi, signer);

const salt = ethers.constants.HashZero;
const bytecodeUint8Array = utils.hashBytecode(guardianStorageArtifact.deployedBytecode)
console.log(bytecodeUint8Array)
const bytecodeHash = ethers.utils.keccak256(bytecodeUint8Array)
console.log(bytecodeHash)

const createCall = await contractDeployer.create(salt, bytecodeHash, "0x", {
gasLimit: 200000
});
const receipt = await createCall.wait();
console.log('Transaction confirmed in block:', receipt.blockNumber);
1
  • Instead of using deployedBytecode on the artifact have you tried using the bytecode field instead i.e. guardianStorageArtifact.bytecode? Also have you tried using the hardhat-zksync-deploy plugin which provides a simple interface for deploying contracts?
    – MShakeG
    Commented Sep 6, 2023 at 7:49

1 Answer 1

0

Try this :

const contractDeployerAddress = "your address";
const contractDeployer = new ethers.Contract(contractDeployerAddress, abi.abi, signer);

const bytecode = guardianStorageArtifact.deployedBytecode;

const bytecodeHash = ethers.utils.keccak256(bytecode);

console.log('Bytecode Hash:', bytecodeHash);

const salt = ethers.utils.randomBytes(32); 

const createCall = await contractDeployer.create(salt, bytecodeHash, "0x", {
  gasLimit: 200000
});

const receipt = await createCall.wait();
console.log('Transaction confirmed in block:', receipt.blockNumber);

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.