From: Ardis Lu Date: Sun, 18 Jun 2023 03:00:08 +0000 (-0700) Subject: Save hashedBytecode for efficiency X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=cce17a2ea18e7aa54ab95d189ba33c846030a914;p=minimal-create2 Save hashedBytecode for efficiency --- diff --git a/README.md b/README.md index 9d6afa2..455e36a 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ const factory = '0x8137a81A74E2a9d510898B2e3E307e7C33eBad8A'; // Must be the entire creation bytecode for the smart contract you want to deploy, including constructor arguments const bytecode = '0x385f818153f3'; // minimal-contract-deployment.evm, compiled +const hashedBytecode = ethers.keccak256(bytecode); // Hash it once and save for efficiency // Simple regex to match the desired CREATE2 address const requirement = /^0xbeef/; @@ -60,7 +61,7 @@ const requirement = /^0xbeef/; let salt = 1; while (true) { const paddedSalt = `0x${salt.toString(16).padStart(64, '0')}`; - const addr = ethers.getCreate2Address(factory, paddedSalt, ethers.keccak256(bytecode)); + const addr = ethers.getCreate2Address(factory, paddedSalt, hashedBytecode); if (requirement.test(addr)) { console.log({factory, paddedSalt, bytecode, addr}); break;