🪝 Hooks
Add custom logic before minting license tokens or registering derivatives.
Hooks allow developers to create custom implementations, restrictions, and functionality upon minting License Tokens or registering derivatives.
There are two types of hooks:
- Licensing Hooks: allow you to add custom logic before minting license tokens (and registering derivatives). For example, requesting a dynamic price, limiting the amount of license tokens that can be minted, whitelists, etc. Licensing Hooks can be added / modified on a licensing config at any point.
- Commercializer Checker Hooks: similar to Licensing Hooks, however they are directly a part of the license terms and do not change. You also cannot return a custom minting fee.
Licensing Hooks
These are contracts that implement the ILicensingHook
interface, which extends from IModule
.
Most importantly, a Licensing Hook implements a beforeMintLicenseTokens
function, which is a function that is called before a License Token is minted to implement custom logic and determine the final totalMintingFee
of that License Token.
View the ILicensingHook
smart contract
here.
Note that it returns the totalMintingFee
. You may be wondering, “I can set the minting fee in the License Terms, in the LicenseConfig
, and return a dynamic price from beforeMintLicenseTokens
. What will the final minting fee actually be?” Here is the priority:
Minting Fee | Importance |
---|---|
The totalMintingFee returned from beforeMintLicenseTokens | Highest Priority |
The mintingFee set in the LicenseConfig | ⬇️ |
The mintingFee set in the License Terms | Lowest Priority |
Beware of potentially malicious implementations of external license hooks. Please first verify the code of the hook you choose because it may be not reviewed or audited by the Story team.
Available Hooks
Below are available hooks deployed on our protocol that you can use.
View the deployed addresses for these hooks here.
Hook | Description | Contract Code |
---|---|---|
LockLicenseHook | Stop the minting of license tokens or registering new derivatives. | View here ↗️ |
TotalLicenseTokenLimitHook | Set a limit on the amount of license tokens that can be minted, updatable at any time. | View here ↗️ |
Implementing the Hooks
SDK Code Example
A working TypeScript SDK code example that shows how to implement a licensing hook. More specifically, how to limit the # of licenses that can be minted.
Solidity Code Example
A working Solidity code example that shows how to implement a licensing hook. More specifically, how to limit the # of licenses that can be minted.
Licensing Hooks are ultimately a smart contract that implements the ILicensingHook
interface. You can view the interface here. We have a few Licensing Hooks deployed already (view the chart above).
In order to actually use a Licensing Hook, you must set it in the Licensing Config, which is basically a set of configurations that you set on License Terms when attaching terms to an IP Asset.
Create Licensing Config
First you have to create a Licensing Config:
Set the Licensing Config
Next, we’ll set the Licensing Config on the License Terms. In the following example, we’ll show this happening upon registering the IP Asset:
This code snippet requires a bit of setup, and it meant for developers who already understand how to setup the TypeScript SDK. If you want to learn more, check out the working code example.
This uses the mintAndRegisterIpAssetWithPilTerms
method found here.
Set the Limit to 1
Now that we have set the Licensing Config on our terms, we can call the setTotalLicenseTokenLimit
function on the hook and set the max # of licenses that can be minted to 1.
There is no Story SDK method for this, so you’ll have to use viem’s writeContract
method.
Commercializer Checker Hooks
Documentation coming soon. If you have questions in the meantime, ask in the Builder’s Discord.