Sample code for Fully-on-chain NFT with Three.js, using PNG image compression instead of gzip.
I referred to ROSES by @dhof and
RollerCoaster by @xtremetom.
git clone https://github.com/NowAndNawoo/on-chain-threejs-png.git
cd on-chain-threejs-png
npm install
cp .env.sample .env
Generate html/Sample1/dist/bundle.js
using Webpack.
Three.js, OrbitControls.js, index.js, and texture images are bundled into one JavaScript file.
npm run build -w html/Sample1
Convert html/Sample1/dist/bundle.js
to output/sample1.png
.
npx hardhat run scripts/create-png.ts
Compress output/sample1.png
and save it as output/sample1.min.png
.
I converted the 471KB JS file to a 416KB PNG file using Jimp, then compressed it down to 127KB using ImageOptim.
Deploy the two contracts, upload the Base64-encoded PNG, and mint.
npx hardhat run scripts/deploy.ts --network goerli
See Appendix for more information about RollerCoaster.