// Extremely naive implementation of "hot reloading" (basically just autorefreshing) a web server that compiles a solidity contract with Hardhat, then outputs the rendered string into HTML. // This file should be placed into the "scripts" folder inside of your standard Hardhat project. const express = require('express') const hre = require('hardhat') const app = express() app.get('/', async (_, res) => { try { // will recompile if there are changes await hre.run('compile') // Grab SVG content from renderer const Renderer = await hre.ethers.getContractFactory('Renderer') const renderer = await Renderer.deploy() await renderer.deployed() const toRender = await renderer.render() // Will refresh every 1 second res.send(`
${toRender} `) } catch (e) { // in case you grab compiler errors res.send(` ${e} `) } }) app.listen(3000, () => { console.log('server started') })