In this tutorial, you will learn how to license and protect DALL·E 2 AI-Generated images by registering it on Story.

The Explanation

Let’s say you generate an image using 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 DALL·E 2 AI-Generated image so that if others want to use it, they must properly license it from you.

In order to register that IP on Story, you first need to mint an NFT to represent that IP, and then register that NFT on Story, turning it into an IP Asset.

0. Before you Start

There are a few steps you have to complete before you can start the tutorial.

  1. You will need to install Node.js and npm. If you’ve coded before, you likely have these.
  2. Add your Story Network Testnet wallet’s private key to .env file:
.env
WALLET_PRIVATE_KEY=
  1. Go to Pinata and create a new API key. Add the JWT to your .env file:
.env
PINATA_JWT=
  1. Go to OpenAI and create a new API key. Add the new key to your .env file:

OpenAI Credits

In order to generate an image, you’ll need OpenAI credits. If you just created an account, you will probably have a free trial that will give you a few credits to start with.

.env
OPENAI_API_KEY=
  1. Add your preferred RPC URL to your .env file. You can just use the public default one we provide:
.env
RPC_PROVIDER_URL=https://aeneid.storyrpc.io
  1. Install the dependencies:
Terminal
npm install @story-protocol/core-sdk pinata-web3 viem openai

1. Generate an Image

In a main.ts file, add the following code to generate an image:

main.ts
import OpenAI from "openai";

async function main() {
  const openai = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY,
  });

  const image = await openai.images.generate({
    model: "dall-e-2",
    prompt: "A cute baby sea otter",
  });

  console.log(image.data[0].url); // the url to the newly created image
}

main();

2. Set up your Story Config

In a utils.ts file, add the following code to set up your Story Config:

Associated docs: TypeScript SDK Setup

utils.ts
import { StoryClient, StoryConfig } from "@story-protocol/core-sdk";
import { http } from "viem";
import { privateKeyToAccount, Address, Account } from "viem/accounts";

const privateKey: Address = `0x${process.env.WALLET_PRIVATE_KEY}`;
export const account: Account = privateKeyToAccount(privateKey);

const config: StoryConfig = {
  account: account,
  transport: http(process.env.RPC_PROVIDER_URL),
  chainId: "aeneid",
};
export const client = StoryClient.newClient(config);

3. Set up your IP Metadata

View the IPA Metadata Standard and construct your metadata for your IP. Back in the main.ts file, properly format your metadata as shown below:

main.ts
import OpenAI from "openai";
import { client, account } from "./utils";

async function main() {
  // previous code here ...

  const ipMetadata = {
    title: "Baby Sea Otter",
    description: "A baby sea otter generated with DALL·E.",
    createdAt: "1728401700",
    image: image.data[0].url,
    imageHash: "0x...", // a hash of the image
    mediaUrl: image.data[0].url,
    mediaHash: "0x...", // a hash of the image
    mediaType: "image/png",
    creators: [
      {
        name: "Jacob Tucker",
        address: "0x67ee74EE04A0E6d14Ca6C27428B27F3EFd5CD084",
        description: "A cool dev rel person.",
        contributionPercent: 100,
        socialMedia: [
          {
            platform: "Twitter",
            url: "https://x.com/jacobmtucker",
          },
        ],
      },
    ],
  };
}

main();

4. Set up your NFT Metadata

The NFT Metadata follows the ERC-721 Metadata Standard.

main.ts
import OpenAI from "openai";
import { client, account } from "./utils";

async function main() {
  // previous code here ...

  const nftMetadata = {
    name: "Image Ownership NFT",
    description:
      "This NFT represents ownership of the image generated by Dall-E 2",
    image: image.data[0].url,
    attributes: [
      {
        key: "Model",
        value: "dall-e-2",
      },
      {
        key: "Prompt",
        value: "A cute baby sea otter",
      },
    ],
  };
}

main();

5. Upload & Register IP

Now that we have all of our metadata set up, you can easily complete this tutorial by going to Register an IP Asset and completing steps 3 (Upload your IP and NFT Metadata to IPFS) & 4 (Register an NFT as an IP Asset).

Once you have done that, you should see a console log with a link to our IP-explorer that shows your registered AI generated image.

6. Done!