Skip to main content

IPAssetClient

Methods

  • registerIpAsset
  • registerDerivativeIpAsset
  • linkDerivative

registerIpAsset

Register your IP as an 🧩 IP Asset. It supports the following workflows:
  1. Register an IP Asset 1a. register an existing NFT as an IP Asset 1b. mint a new NFT and register as an IP Asset
  2. Attach license terms to the IP Asset
  3. Distribute royalty tokens
Note that this function will also set the underlying NFT’s tokenUri to whatever is passed under ipMetadata.nftMetadataURI.
MethodType
registerIpAsset(request: RegisterIpAssetRequest) => Promise<RegisterIpAssetResponse>
Parameters:
  • request.nft: You have two options here
    • { type: "minted", nftContract: Address, tokenId: number | bigint }: Register an existing NFT as an IP Asset. This is typically the harder option because you need to already have an NFT minted.
    • { type: "mint", spgNftContract: Address, recipient?: Address, allowDuplicates?: boolean }: Mint a new NFT and register as an IP Asset. This is typically the easier option because you don’t need to worry about already having an NFT minted. Just create an spgNftContract, or use a default one, to mint for you.
  • request.licenseTermsData: If you want to attach license terms.
    • request.licenseTermsData.terms: The license terms to attach to the IP Asset.
    • request.licenseTermsData.licensingConfig: The licensing config to attach to the IP Asset.
    • request.licenseTermsData.maxLicenseTokens: The max number of license tokens that can be minted from this license term.
  • request.royaltyShares: If you want to distribute royalty tokens out.
    • request.royaltyShares.recipient: The address of the recipient of the royalty shares.
    • request.royaltyShares.percentage: The percentage of the royalty shares.
  • request.ipMetadata: The metadata of the IP Asset
    • request.ipMetadata.ipMetadataURI: The URI of the metadata for the IP.
    • request.ipMetadata.ipMetadataHash: The hash of the metadata for the IP.
    • request.ipMetadata.nftMetadataURI: The URI of the metadata for the NFT.
    • request.ipMetadata.nftMetadataHash: The hash of the metadata for the IP NFT.
  • request.deadline: The deadline for the signature in milliseconds. Defaults to 1000.
import { PILFlavor, WIP_TOKEN_ADDRESS } from "@story-protocol/core-sdk";
import { toHex } from "viem";

// an example of an SPG NFT contract address
// you can create one via `client.nftClient.createNFTCollection`
const spgNftContract = "0xc32A8a0FF3beDDDa58393d022aF433e78739FAbc";

const response = await client.ipAsset.registerIpAsset({
  nft: { type: "mint", spgNftContract: spgNftContract },
  licenseTermsData: [
    {
      terms: PILFlavor.creativeCommonsAttribution({
        currency: WIP_TOKEN_ADDRESS,
        // RoyaltyPolicyLAP address from https://docs.story.foundation/docs/deployed-smart-contracts
        royaltyPolicy: "0xBe54FB168b3c982b7AaE60dB6CF75Bd8447b390E",
      }),
    },
    {
      terms: PILFlavor.commercialRemix({
        defaultMintingFee: 10000n,
        commercialRevShare: 20, // 20%
        currency: WIP_TOKEN_ADDRESS,
        // RoyaltyPolicyLAP address from https://docs.story.foundation/docs/deployed-smart-contracts
        royaltyPolicy: "0xBe54FB168b3c982b7AaE60dB6CF75Bd8447b390E",
      }),
      maxLicenseTokens: 100,
    },
  ],
  royaltyShares: [
    {
      recipient: "0x123...",
      percentage: 10,
    },
  ],
  ipMetadata: {
    ipMetadataURI:
      "https://ipfs.io/ipfs/bafkreiardkgvkejqnnkdqp4pamkx2e5bs4lzus5trrw3hgmoa7dlbb6foe",
    ipMetadataHash: toHex("test-metadata-hash", { size: 32 }),
    nftMetadataURI:
      "https://ipfs.io/ipfs/bafkreicexrvs2fqvwblmgl3gnwiwh76pfycvfs66ck7w4s5omluyhti2kq",
    nftMetadataHash: toHex("test-nft-metadata-hash", { size: 32 }),
  },
});

console.log(
  `Root IPA created at transaction hash ${response.txHash}, IPA ID: ${response.ipId}`
);

registerDerivativeIpAsset

Register an IP as a derivative of another IP Asset. This function allows you to use an existing license token to register as derivative, or it will mint one for you. To register an IP as a derivative, it must be an IP Asset itself. So this function allows you to register an existing NFT as an IP Asset (which will be the derivative), or mint a new NFT for you (and register it as a derivative).
MethodType
registerDerivativeIpAsset(request: RegisterDerivativeIpRequest) => Promise<RegisterDerivativeIpResponse>
Parameters:
  • request.nft: You have two options here
    • { type: "minted", nftContract: Address, tokenId: number | bigint }: Register an existing NFT as an IP Asset. This is typically the harder option because you need to already have an NFT minted.
    • { type: "mint", spgNftContract: Address, recipient?: Address, allowDuplicates?: boolean }: Mint a new NFT and register as an IP Asset. This is typically the easier option because you don’t need to worry about already having an NFT minted. Just create an spgNftContract, or use a default one, to mint for you.
  • request.licenseTokenIds: If you want to use a license token to register as derivative.
  • request.derivData: If you want to mint a license token for you.
    • request.derivData.parentIpIds: The IDs of the parent IPs to link the registered derivative IP.
    • request.derivData.licenseTermsIds: The IDs of the license terms to be used for the linking.
  • request.royaltyShares: If you want to distribute royalty tokens out.
    • request.royaltyShares.recipient: The address of the recipient of the royalty shares.
    • request.royaltyShares.percentage: The percentage of the royalty shares.
  • request.maxRts: The maximum number of royalty tokens that can be distributed to the external royalty policies. Must be between 0 and 100,000,000. Recommended for simplicity: 100_000_000
  • request.ipMetadata: The metadata of the IP Asset
    • request.ipMetadata.ipMetadataURI: The URI of the metadata for the IP.
    • request.ipMetadata.ipMetadataHash: The hash of the metadata for the IP.
    • request.ipMetadata.nftMetadataURI: The URI of the metadata for the NFT.
    • request.ipMetadata.nftMetadataHash: The hash of the metadata for the IP NFT.
  • request.deadline: The deadline for the signature in milliseconds. Defaults to 1000.
import { toHex } from "viem";

// an example of an SPG NFT contract address
// you can create one via `client.nftClient.createNFTCollection`
const spgNftContract = "0xc32A8a0FF3beDDDa58393d022aF433e78739FAbc";

// an example of a parent IP ID
const parentIpId = "0x456...";

// an example of a commercial remix license terms ID
const commercialRemixLicenseTermsId = 5;

const response = await client.ipAsset.registerDerivativeIpAsset({
  nft: { type: "mint", spgNftContract },
  derivData: {
    parentIpIds: [parentIpId],
    licenseTermsIds: [commercialRemixLicenseTermsId],
  },
  ipMetadata: {
    ipMetadataURI:
      "https://ipfs.io/ipfs/bafkreiardkgvkejqnnkdqp4pamkx2e5bs4lzus5trrw3hgmoa7dlbb6foe",
    ipMetadataHash: toHex("test-metadata-hash", { size: 32 }),
    nftMetadataURI:
      "https://ipfs.io/ipfs/bafkreicexrvs2fqvwblmgl3gnwiwh76pfycvfs66ck7w4s5omluyhti2kq",
    nftMetadataHash: toHex("test-nft-metadata-hash", { size: 32 }),
  },
  royaltyShares: [
    {
      recipient: "0x123...",
      percentage: 10,
    },
  ],
});

console.log(
  `Derivative IPA linked to parent at transaction hash ${response.txHash}`
);

linkDerivative

Link an existing derivative IP to a parent IP.
MethodType
linkDerivative(request: LinkDerivativeRequest) => Promise<LinkDerivativeResponse>
Parameters:
  • Without License Tokens
  • With License Tokens
  • request.childIpId: The ID of the child IP.
  • request.licenseTermIds: The IDs of the license terms to be used for the linking.
  • request.parentIpIds: The IDs of the parent IPs.
const response = await client.ipAsset.linkDerivative({
  childIpId: "0xC92EC2f4c86458AFee7DD9EB5d8c57920BfCD0Ba",
  parentIpIds: ["0xC92EC2f4c86458AFee7DD9EB5d8c57920BfCD0Ba"],
  licenseTermsIds: [5],
});

console.log(
  `Derivative IPA linked to parent at transaction hash ${response.txHash}`
);
I