Mint your NFTs with Stable Diffusion
Gelato Team
•
Jun 27, 2023

In the current era of rapid technological evolution, the convergence of AI and web3 presents an intriguing narrative. Rather than a competition, it is a story of synergy, where AI accelerates adoption of decentralized networks by enabling smart contracts to securely interact with machine learning models.
A key advancement here is generative modeling, AI that creates new data from learned patterns. Among these, the diffusion model is particularly powerful—turning random noise into coherent images, guided by prompts when needed.
In this tutorial, we’ll demonstrate how to combine Gelato’s Web3 Functions with StabilityAI’s Stable Diffusion to create NFTs powered by AI-generated art. Stable Diffusion will generate images, while Web3 Functions bridge them into NFTs on-chain.
Workflow
GelatoNft Smart Contract: Mint NFTs with suspense until their reveal.
Stable Diffusion: Generate unique images as NFT metadata.
Gelato’s Web3 Functions: Automate assignment of AI images to NFTs.
Prerequisites
Signed up for the Gelato Web3 Functions beta
Installed Node.js v16+, NPM, and Git
Web3 wallet (e.g. MetaMask)
Accounts on Alchemy, NFT Storage, and Stable Diffusion
Set Up Your Dev Environment
Configure Secrets
Alchemy ID
Private Key (from MetaMask)
Stable Diffusion API Key
NFT.Storage API Key
Fill these into .env
files as per templates provided.
GelatoNft Contract
The contract mints NFTs with a placeholder URI until revealed by Gelato Web3 Functions.
Web3 Function Flow
Validate Inputs: Fetch contract address and secrets for NFT.Storage & Stable Diffusion.
Process NFTs: Identify unrevealed tokens.
Generate Image: Call Stable Diffusion API with description prompts.
Upload Metadata: Store result on IPFS via NFT.Storage.
Update Contract: Call
revealNft
with tokenId and metadata URL.
Example: Image Generation
Upload to IPFS
Deploy & Run
Deploy Contract:
Deploy Web3 Function:
Create Task: Visit Gelato App with the IPFS CID to schedule your function.
Monitor Your Task
Executions over time
Logs and outputs
Secrets and storage state
Conclusion
By combining Stable Diffusion AI with Gelato’s Web3 Functions, you can mint NFTs with dynamic AI-generated art seamlessly connected to your smart contracts. This blend of AI and blockchain enriches NFT experiences with automation, creativity, and decentralization.
Dive Deeper with Gelato
Join the community on Discord. Web3 Functions are live in private beta. Read the documentation and explore the tutorials. Apply here to be among the first testers.