Template for creating onchain SVGs
- Install Foundry.
- Install Yarn Classic.
- Install dependencies with
forge install && yarn install - Run
forge test --ffito output an svg. Each time you run the test inSVG.t.solwill outputonchain.svgto/srcand open it in your default app for SVGs. Browser is a good choice for SVG reader. - Change the data in
SVG.solto output the SVG of your dreams.
Note: foundry.toml's allows Forge to find libs in /node_modules without an explicit remapping. For this reason there is no remappings.txt needed.
To test rendering Juicebox Project Handles in your SVG:
- Switch to the
project-handlesbranch. - Run
forge test --fork-url $RPC_URL -v --via-ir --ffi, replacing$RPC_URLwith your own RPC provider and API key. API providers include Infura and Alchemy. An RPC url might look likehttps://mainnet.infura.io/v3/xyzabc123xyzabc123xyzabc123. - If you append
--fork-block-number BLOCK_NUMBERto the above, replacingBLOCK_NUMBERwith a recent block height, Forge will cache the fork and the tests will run faster. Do not be surprised if values don't change when you set a new project handle onchain. - To fork Goerli instead of Mainnet, first swap which lines are commented in
SVG.t.sol'ssetUp()function, then run the command in step 2 with a Goerli RPC URL.
More information on Project Handles including its testnet address is available in the Juicebox Docs.
You can incorporate other onchain assets, such as Peripheralist's Capsules typeface, into your onchain SVG. The entire font is stored onchain, so you can incorporate it into your SVG art without worrying about offchain depenencies such as the fonts built-in to the viewer's operating system, or a popular Fonts API being unavailable when the SVG is viewed.
To test rendering an SVG using Capsules:
- Switch to the
typefacebranch - Run
forge test --fork-url $RPC_URL -v --via-ir --ffi, replacing$RPC_URLwith your own RPC provider and API key.
This repo draws on work by Jango, DrGorilla, Peripheralist, and Jeton Connu.