Learn how to Attach License Terms to an IP Asset in TypeScript.
This section demonstrates how to attach License Terms to an IP Asset. By attaching terms, users can publicly mint License Tokens (the on-chain “license”) with those terms from the IP.
We should mention that you do not need an existing IP Asset to attach terms to it. As we saw in the previous section, you can register an IP Asset and attach terms to it in the same transaction.
In order to attach terms to an IP Asset, let’s first create them!License Terms are a configurable set of values that define restrictions on licenses minted from your IP that have those terms. For example, “If you mint this license, you must share 50% of your revenue with me.” You can view the full set of terms in PIL Terms.
If License Terms already exist on our protocol for the identical set of parameters you intend to create, it is unnecessary to create it again and the function will simply return the existing licenseTermsId and an undefined txHash. License Terms are protocol-wide, so you can use existing License Terms by its licenseTermsId.
Below is a code example showing how to create new terms:
As you see above, you have to choose between a lot of terms.We have convenience functions to help you register new terms. We have created PIL Flavors, which are pre-configured popular combinations of License Terms to help you decide what terms to use. You can view those PIL Flavors and then register terms using the following convenience functions:
Non-Commercial Social Remixing
Free remixing with attribution. No commercialization.
Commercial Use
Pay to use the license with attribution, but don’t have to share revenue.
Commercial Remix
Pay to use the license with attribution and pay % of revenue earned.
Creative Commons Attribution
Free remixing and commercial use with attribution.
You can easily register a flavor of terms like so:
main.ts
Copy
Ask AI
import { PILFlavor, WIP_TOKEN_ADDRESS } from "@story-protocol/core-sdk";import { parseEther } from "viem";// you should already have a client set up (prerequisite)import { client } from "./utils";async function main() { const response = await client.license.registerPILTerms( PILFlavor.commercialRemix({ commercialRevShare: 5, defaultMintingFee: parseEther("1"), // 1 $IP currency: WIP_TOKEN_ADDRESS, }) ); console.log( `PIL Terms registered at transaction hash ${response.txHash}, License Terms ID: ${response.licenseTermsId}` );}main();
import { LicenseTerms } from "@story-protocol/core-sdk";import { zeroAddress } from "viem";// you should already have a client set up (prerequisite)import { client } from "./utils";async function main() { // previous code here ... const response = await client.license.attachLicenseTerms({ // insert your newly created license terms id here licenseTermsId: LICENSE_TERMS_ID, // insert the ipId you want to attach terms to here ipId: "0x4c1f8c1035a8cE379dd4ed666758Fb29696CF721", }); if (response.success) { console.log( `Attached License Terms to IPA at transaction hash ${response.txHash}.` ); } else { console.log(`License Terms already attached to this IPA.`); }}main();