/** * Deploy Thirdweb infra on Chain 138 using bytecode/ABI from `forge build` (avoids Hardhat compiling * Thirdweb's duplicate `library Address` from OZ vs thirdweb/lib). */ require("dotenv").config(); const fs = require("fs"); const path = require("path"); const hre = require("hardhat"); function findForgeArtifact(contractName) { const outDir = path.join(__dirname, "..", "out"); const matches = []; function walk(dir) { if (!fs.existsSync(dir)) return; for (const ent of fs.readdirSync(dir, { withFileTypes: true })) { const p = path.join(dir, ent.name); if (ent.isDirectory()) walk(p); else if (ent.name === `${contractName}.json`) matches.push(p); } } walk(outDir); if (matches.length === 0) { throw new Error( `No forge artifact for ${contractName} under out/. Run: cd thirdweb-core-2103-test && forge build` ); } if (matches.length > 1) { throw new Error(`Multiple ${contractName}.json artifacts: ${matches.join(", ")}`); } const raw = fs.readFileSync(matches[0], "utf8"); return JSON.parse(raw); } async function main() { const signers = await hre.ethers.getSigners(); if (signers.length === 0) { throw new Error( "No signer: set PRIVATE_KEY (32-byte hex) in .env for chain138ThirdwebCore." ); } const deployer = signers[0]; console.log("Deployer", deployer.address); const gasPrice = 1_000_000_000n; const opts = { gasPrice }; const ForwarderArt = findForgeArtifact("Forwarder"); const TWRegistryArt = findForgeArtifact("TWRegistry"); const TWFactoryArt = findForgeArtifact("TWFactory"); const ContractPublisherArt = findForgeArtifact("ContractPublisher"); const Forwarder = new hre.ethers.ContractFactory( ForwarderArt.abi, ForwarderArt.bytecode.object, deployer ); const forwarder = await Forwarder.deploy(opts); await forwarder.waitForDeployment(); const forwarderAddr = await forwarder.getAddress(); console.log("Forwarder", forwarderAddr); const TWRegistry = new hre.ethers.ContractFactory( TWRegistryArt.abi, TWRegistryArt.bytecode.object, deployer ); const registry = await TWRegistry.deploy(forwarderAddr, opts); await registry.waitForDeployment(); const registryAddr = await registry.getAddress(); console.log("TWRegistry", registryAddr); const TWFactory = new hre.ethers.ContractFactory( TWFactoryArt.abi, TWFactoryArt.bytecode.object, deployer ); const factory = await TWFactory.deploy(forwarderAddr, registryAddr, opts); await factory.waitForDeployment(); console.log("TWFactory", await factory.getAddress()); const ContractPublisher = new hre.ethers.ContractFactory( ContractPublisherArt.abi, ContractPublisherArt.bytecode.object, deployer ); const publisher = await ContractPublisher.deploy( deployer.address, forwarderAddr, hre.ethers.ZeroAddress, opts ); await publisher.waitForDeployment(); console.log("ContractPublisher", await publisher.getAddress()); } main().catch((e) => { console.error(e); process.exit(1); });