Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hre.ethers.ContractFactory and hre.zksyncEthers.ContractFactory don't work with zksync nodes #1420

Closed
mmv08 opened this issue Sep 18, 2024 · 4 comments

Comments

@mmv08
Copy link

mmv08 commented Sep 18, 2024

🐛 Bug Report for hardaht-zksync plugins

💥 Plugin name

I guess it's hardhat-zksync-ethers

📝 Description

I needed to deploy a contract from the bytecode in tests, and I tried using:

  1. hre.ethers.ContractFactory (I thought there was an interop)
  2. hre.zksyncEthers.ContractFactory
  3. signer.sendTransaction({ data: deploymentBytecode }) (I thought there was an interop)

All approaches failed with an error:

 (error={ "code": 3, "message": "Failed to serialize transaction: toAddressIsNull" }

Importing the ContractFactory directly from zksync-ethers worked.

🔄 Reproduction Steps

So, for me, the main bug here is that `hre.zksyncEthers.ContractFactory is not working as expected, all others are nice-to-haves. Therefore I'm only describing reproduction steps for that issue.

  1. In any hardhat project, create a helper function
export const getContractFactory = (
    hre: HardhatRuntimeEnvironment,
    abi: Interface | InterfaceAbi,
    bytecode: string,
    contractRunner?: ContractRunner,
) => {
    if (hre.network.zksync) {
        return new hre.zksyncEthers.ContractFactory(abi, bytecode, contractRunner);
    }

    return new hre.ethers.ContractFactory(abi, bytecode, contractRunner);
};
  1. Attempt to deploy any contract with the function like so:
const contractAddress = await getContractFactory(hre, abi, bytecode, signer)
                    .deploy()
                    .then((c) => c?.getAddress());
  1. Observe the error

🤔 Expected Behavior

The contract is deployed and no error is thrown

😯 Current Behavior

 (error={ "code": 3, "message": "Failed to serialize transaction: toAddressIsNull" }

🖥️ Environment

  • Node version: v20.10.0
  • Operating System & Version: macOS Sequoia 15.0 arm64
  • Other relevant environment details: All the latest hardhat/zksync-related package versions at the moment of writing the issue.
@kiriyaga-txfusion
Copy link
Contributor

Hello @mmv08 ,

Which versions of zksync-ethers and hardhat-zksync-ethers are you using? Could you provide us with the GitHub repository so we can try it ourselves?

@mmv08
Copy link
Author

mmv08 commented Sep 18, 2024

Hello @mmv08 ,

Which versions of zksync-ethers and hardhat-zksync-ethers are you using? Could you provide us with the GitHub repository so we can try it ourselves?

zksync-ethers@6.11.2
@matterlabs/hardhat-zksync-ethers@1.2.0

For the github repo you can try safe-global/safe-smart-account@7975f52 (notice the commit hash)

The function for getting the contract factory is in test/utils/contracts.ts and you can run the zk test suite with npm run test:zk

@nikola-bozin-txfusion
Copy link
Contributor

Hey @mmv08, please use the latest release of @matterlabs/hardhat-zksync-ethers, version 1.2.1.

Also, in your code, you dont have to use if statement to check weather network is zksync or not.
You can just use hre.ethers and it will execute proper functionality based on current network.

@mmv08
Copy link
Author

mmv08 commented Sep 19, 2024

thnaks, I've just tested it and it works

@mmv08 mmv08 closed this as completed Sep 19, 2024
mmv08 added a commit to safe-global/safe-smart-account that referenced this issue Sep 19, 2024
This PR:
- Partially solves
#767 (test
updates for `SafeToL2Upgrade` are still pending)
- It is based on version 1.5.0 because 1.4.1 cannot be compiled at the
moment because we used `.send` in there, and hardhat zksync compiler
plugin needs to be updated to support suppressing errors. I will
cherry-pick it later.
- I updated the `deployContract` function name and return type to be
more self-explanatory
- The main changes were around adding zksync compatible bytecode and
also using the ContractFactory from the "zksync-ethers" package because
in ZkSync you need to interact with a system contract to deploy
contracts and not just send a transaction with the bytecode and
`to` address omitted.

One bug found: matter-labs/hardhat-zksync#1420
mmv08 added a commit to safe-global/safe-smart-account that referenced this issue Sep 26, 2024
This PR:
- Partially solves
#767 (test
updates for `SafeToL2Upgrade` are still pending)
- It is based on version 1.5.0 because 1.4.1 cannot be compiled at the
moment because we used `.send` in there, and hardhat zksync compiler
plugin needs to be updated to support suppressing errors. I will
cherry-pick it later.
- I updated the `deployContract` function name and return type to be
more self-explanatory
- The main changes were around adding zksync compatible bytecode and
also using the ContractFactory from the "zksync-ethers" package because
in ZkSync you need to interact with a system contract to deploy
contracts and not just send a transaction with the bytecode and
`to` address omitted.

One bug found: matter-labs/hardhat-zksync#1420
migramirez2 added a commit to migramirez2/Safe-smart-account that referenced this issue Nov 5, 2024
This PR:
- Partially solves
safe-global/safe-smart-account#767 (test
updates for `SafeToL2Upgrade` are still pending)
- It is based on version 1.5.0 because 1.4.1 cannot be compiled at the
moment because we used `.send` in there, and hardhat zksync compiler
plugin needs to be updated to support suppressing errors. I will
cherry-pick it later.
- I updated the `deployContract` function name and return type to be
more self-explanatory
- The main changes were around adding zksync compatible bytecode and
also using the ContractFactory from the "zksync-ethers" package because
in ZkSync you need to interact with a system contract to deploy
contracts and not just send a transaction with the bytecode and
`to` address omitted.

One bug found: matter-labs/hardhat-zksync#1420
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants