Template for creating onchain SVGs
- Install Foundry.
- Install Yarn Classic.
- Install dependencies with
forge install && yarn install
- Run
forge test --ffi
to output an svg. Each time you run the test inSVG.t.sol
will outputonchain.svg
to/src
and open it in your default app for SVGs. Browser is a good choice for SVG reader. - Change the data in
SVG.sol
to 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-handles
branch. - Run
forge test --fork-url $RPC_URL -v --via-ir --ffi
, replacing$RPC_URL
with 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_NUMBER
to the above, replacingBLOCK_NUMBER
with 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
typeface
branch - Run
forge test --fork-url $RPC_URL -v --via-ir --ffi
, replacing$RPC_URL
with your own RPC provider and API key.
This repo draws on work by Jango, DrGorilla, Peripheralist, and Jeton Connu.