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.
Prerequisites
There are a few steps you have to complete before you can start the tutorial.
- Complete the TypeScript SDK Setup
1. Before We Start
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.
2. Register License Terms
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:
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() {
const licenseTerms: LicenseTerms = {
defaultMintingFee: 0n,
// must be a whitelisted revenue token from https://docs.story.foundation/developers/deployed-smart-contracts
// in this case, we use $WIP
currency: "0x1514000000000000000000000000000000000000",
// RoyaltyPolicyLAP address from https://docs.story.foundation/developers/deployed-smart-contracts
royaltyPolicy: "0xBe54FB168b3c982b7AaE60dB6CF75Bd8447b390E",
transferable: false,
expiration: 0n,
commercialUse: false,
commercialAttribution: false,
commercializerChecker: zeroAddress,
commercializerCheckerData: "0x",
commercialRevShare: 0,
commercialRevCeiling: 0n,
derivativesAllowed: false,
derivativesAttribution: false,
derivativesApproval: false,
derivativesReciprocal: false,
derivativeRevCeiling: 0n,
uri: "",
};
const response = await client.license.registerPILTerms({
...licenseTerms,
});
console.log(
`PIL Terms registered at transaction hash ${response.txHash}, License Terms ID: ${response.licenseTermsId}`
);
}
main();
2a. PIL Flavors
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:
You can easily register a flavor of terms like so:
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();
3. Attach License Terms
Now that we have created terms and have the associated licenseTermsId
, we can attach them to an existing IP Asset like so:
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();
3. Mint a License
Now that we have attached License Terms to our IP, the next step is minting a License Token, which we’ll go over on the next page.