Register & Monetize Stability Images
Learn how to register, protect, and monetize Stability AI-Generated images on Story.
In this tutorial, you will learn how to:
- Generate an image with Stability AI
- Upload your image to Pinata IPFS
- Register your image as IP on Story
- Attach License Terms to your IP
The Explanation
Let’s say you generate an image using Stability AI. Without adding a proper license to your image, others could use it freely. In this tutorial, you will learn how to add a license to your Stability AI-Generated image so that if others want to use it, they must properly license it from you.
0. Before you Start
There are a few steps you have to complete before you can start the tutorial.
- You will need to install Node.js and npm. If you’ve coded before, you likely have these.
- Add your Story Network Testnet wallet’s private key to
.env
file:
- Go to the Pinata dashboard and create a new API key and a gateway. Add the JWT along with the gateway to your
.env
file:
- Go to Stability and create a new API key. Add the new key to your
.env
file:
Stability Credits
In order to generate an image, you’ll need Stability credits. If you just created an account, you will probably have a free trial that will give you a few credits to start with.
- Add your preferred RPC URL to your
.env
file. You can just use the public default one we provide:
- Install the dependencies:
1. Generate an Image
You can follow the Stability API Reference to use the model of your choice. For this tutorial, we’ll be using Stability’s Stable Image Core generate endpoint to generate an image. The below is taken directly from their documentation.
Create a main.ts
file and add the following code:
1.5. (Optional) Condense the Image
Stability generates images that are heavy in size, and therefore expensive to store. Optionally, we can condense the produced image for faster loading speeds and less expensive storage costs.
2. Store Image in IPFS
Now that we have our image, we need to store it on IPFS so we can get a URL back to access it. In this tutorial we’ll be using Pinata, a decentralized storage solution that makes storing images easy.
In a separate file uploadToIpfs.ts
, create a function uploadBlobToIPFS
that uploads our buffer to IPFS:
Back in the main file, call the uploadBlobToIPFS
function to store our image:
3. Set up your Story Config
Now that we have generated and stored our image, we can register the image as IP on Story. First, let’s set up our config. In a utils.ts
file, add the following code:
Associated docs: TypeScript SDK Setup
4. Set up your IP Metadata
View the IPA Metadata Standard and construct the metadata for your IP. Properly format your metadata as shown below:
5. Set up your NFT Metadata
The NFT Metadata follows the ERC-721 Metadata Standard.
6. Upload your IP and NFT Metadata to IPFS
In the uploadToIpfs.ts
file, create a function to upload your IP & NFT Metadata objects to IPFS:
You can then use that function to upload your metadata, as shown below:
7. Create License Terms
When registering your image on Story, you can attach License Terms to the IP. These are real, legally binding terms enforced on-chain by the Licensing Module, disputable by the Dispute Module, and in the worst case, able to be enforced off-chain in court through traditional means.
Let’s say we want to monetize our image such that every time someone wants to use it (on merch, advertisement, or whatever) they have to pay an initial minting fee of 10 $WIP. Additionally, every time they earn revenue on derivative work, they owe 5% revenue back as royalty.
8. Register an NFT as an IP Asset
Next we will mint an NFT, register it as an IP Asset, set License Terms on the IP, and then set both NFT & IP metadata.
Luckily, we can use the mintAndRegisterIp
function to mint an NFT and register it as an IP Asset in the same transaction.
This function needs an SPG NFT Contract to mint from. For simplicity, you can use a public collection we have created for you on Aeneid testnet: 0xc32A8a0FF3beDDDa58393d022aF433e78739FAbc
.
Associated Docs: ipAsset.mintAndRegisterIp
9. Done!
Congratulations! Now your image is registered on Story with commercial license terms.