UNPKG

hardhat-deployed-records

Version:
2 lines (1 loc) 1.15 kB
export declare const indexFile = "import hre from \"hardhat\";\nimport fs from \"fs\";\nimport path from \"path\";\n\n// read json file\nfunction readSync() {\n try {\n const content = fs.readFileSync(manifest, \"utf-8\");\n return JSON.parse(content);\n } catch (err) {\n console.error(err);\n }\n}\n\n// write json file\nfunction saveSync() {\n const content = JSON.stringify(data, null, 2);\n try {\n fs.writeFileSync(manifest, content);\n } catch (err) {\n console.error(err);\n }\n}\n\nconst network = hre.network.name;\nconsole.log(\"current network: \", network);\n\n// const [signer] = await ethers.getSigners();\n// console.log(\"current signer: \", signer.address);\n\nconst manifest = path.join(__dirname, network, \"contracts.json\");\nconst data = readSync();\n\nconst deployed = {\n contracts: data,\n {{#contracts}}\n set{{name}}Contract: function (addr: string) {\n this.contracts{{#path}}[\"{{.}}\"]{{/path}} = addr;\n saveSync();\n },\n get{{name}}Contract: function (): string {\n return this.contracts{{#path}}[\"{{.}}\"]{{/path}};\n },\n {{/contracts}}\n};\n\nexport default deployed;";