Closed oveddan closed 2 weeks ago
ok nevermind i figured out what my issue is! the contract with that bytecode hash must be already deployed before using its hash to deploy deterministically. pretty cool :)
Hey @oveddan, glad you found a solution, but I think you'd be interested in knowing that you could still do this type of deployment directly from within foundry, without needing the contract to be already deployed (1) or fetching the bytecode hash manually (2).
For issue number 1, you can use zkUseFactoryDep
cheatcode, by specifying the hash of the contract to be deployed.
Meanwhile, for issue number 2, you could either use getCode
to retrieve the bytecode hash and hash it afterwards, or use readFile
& parseJsonBytes
to retrieve the bytecodeHash from the artifact, like what you did initially, but this one will always have the right hash even across different compilations ;)
While writing this, I noticed that you are attempting to do a CREATE2 deployment, in that case you could just simply use new ZkImmutableCreate2Factory{salt: ZK_IMMUTABLE_CREATE2_FACTORY_SALT}();
, this will use the Create2Factory present on ZKsync Era for your deployment (which essentially does the same thing as the contract deployer)
Hope that improves your experience using foundry-zksync
! :)
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.0.2 (953a180 2024-11-05T00:24:47.804587000Z)
What command(s) is the bug in?
forge script --zksync
Operating System
None
Describe the bug
I'm having an issue when deterministically deploying a contract using zksync.
Here is my script:
To get the hash, I went to
zkout/ZkImmutableCreate2Factory/ZkImmutableCreate2Factory.json
and grabbed the hash value, and copied and pasted it into the script above.When I run the script I get the error "script failed: revert: The code hash is not known"
However, in general I want to be able to save the bytecode and bytecode hash, so that in future versions of my code, lets say the foundry version changes and compilation changes, I can load the original bytecode and hash so that I can deploy deterministically to another chain at the same address without working about a recompilation changing the bytecode.
How does foundry zksync look for matching bytecode for a hash? is there a way to pass it in manually so that it doesn't have to rely on compiled contracts in zkout?