Advanced Art - GasFire
What is GasFire
GasFire is a type of Generative Art that visualizes fire. The colors are generated based on the amount of gas consumed by the address minting the NFT on the Ethereum chain. Users who mint are categorized into predefined Tiers based on their gas consumption, and colors corresponding to these Tiers are assigned. The shape of the fire also incorporates a fluctuation, creating a unique shape for each address.
Let's see how GasFire is implemented on the Phi Protocol.
Overview
First, let's take an overview. The main components that need to be developed are the Verifier API and the Render API. Phi Protocol provides a foundation for issuing NFTs using Advanced Art by preparing these two APIs.
The Verifier API is used to correctly verify whether the created Cred meets the conditions. In this case, the Verifier API checks whether the gas consumption on Ethereum is greater than 0. Other Verifier APIs might verify specific on-chain activities (e.g., issuing a specific NFT or performing a certain number of transactions on a specific chain). Additionally, up to 32 bytes of additional data can be used during verification when issuing Advanced Art. By returning this additional data, it can be passed as an argument during the Render API call at minting time. In this case, the gas consumption value (gas_used) obtained from the Etherscan API is returned.
The Render API generates an image based on the eligible address and additional data returned by the Verifier API when it considers the address eligible. The generated image is uploaded to Arweave as the final NFT image data, and the URL is embedded in the contract.
Next, let's look at the implementation of the Verifier API.
Verifier API Implementation
Here is the implementation of the Verifier API endpoint.
The flow of this code is as follows:
Retrieve the
address
from the URL query parameters.Get the signing private key from environment variables.
Get the gas consumption of the target address via the Etherscan API.
If the gas consumption is greater than 0,
mint_eligibility
is set to true.Return the gas consumption value as the value of the
data
field.Use the signing private key to create a signature that includes the values of
address
,mint_eligibility
, and thedata
field, and return it as the value of thesignature
field.
A sample response in JSON format when mint_eligibility
is true and gas_used
is 1052390 would be as follows:
These values are used to verify the contract after it is returned. Verification with a signature other than the address set as the Signer when the Verifier API was registered will fail on the contract, and the Art cannot be minted.
For the implementation of the create_signature
method for signature verification, please refer to the Phi Protocol specifications.
Once the Verifier API is implemented, proceed to the implementation of the Render API.
Render API Implementation
Here is the implementation of the Render API endpoint.
The flow of this code is as follows:
Retrieve the
address
anddata
from the URL query parameters.Implement the backend using TypeScript/NextJS, and initialize the canvas with a size of 512x512 for image generation.
Call the
renderImage
method to draw Advanced Art on the canvas.Encode the drawn image in PNG format and respond with a 200 status.
The renderImage method implements the specific drawing process, which mostly includes the unique processing for Advanced Art.
renderImage overview
Here's an overview of the processes within the renderImage method.
To generate a deterministic and unique Art for the address, a deterministic random number algorithm called XorShift is used. This XorShift initialized with the address will be used as the source of parameters for generating this Art.
The base of the fire image is a predefined set of Bezier curve points. 2 to 4 sets of these points are obtained.
Projection transformations are created and applied to each set of points to add fluctuations to the fire.
The gas consumption passed as an argument is classified into a predefined Tier, and the color corresponding to this Tier is obtained.
Finally, the fire point groups with added fluctuations are combined and drawn using the fire color.
Conclusion
In this article, we explained how to implement GasFire, an example of Advanced Art, on the Phi Protocol.
This time, the implementation was done using TypeScript/NextJS, but as long as the API conforms to the JSON schema defined by Phi Protocol, the language and technologies used are not restricted.
The complete code for GasFire is available on GitHub for reference.
Last updated