]> git.ardis.lu - minimal-create2/commitdiff
Save hashedBytecode for efficiency
authorArdis Lu <ardisglu@gmail.com>
Sun, 18 Jun 2023 03:00:08 +0000 (20:00 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 18 Jun 2023 03:00:08 +0000 (20:00 -0700)
README.md

index 9d6afa205485484aef94d66c6ad291b985f7d067..455e36a18f3a59fffb744dc3cb2a1840a40afa83 100644 (file)
--- 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;
This page took 0.050282 seconds and 4 git commands to generate.