Using the SDK
In this tutorial, you will learn how to send money (“tip”) an IP Asset using the TypeScript SDK.The Explanation
In this scenario, let’s say there is a parent IP Asset that represents Mickey Mouse. Someone else draws a hat on that Mickey Mouse and registers it as a derivative (or “child”) IP Asset. The License Terms specify that the child must share 50% of all commercial revenue (commercialRevShare = 50) with the parent. Someone else (a 3rd party user) comes along and wants to send the derivative 2 $WIP for being really cool.
For the purposes of this example, we will assume the child is already registered as a derivative IP Asset. If you want help learning this, check out Register a Derivative.
- Parent IP ID:
0x42595dA29B541770D9F9f298a014bF912655E183 - Child IP ID:
0xeaa4Eed346373805B377F5a4fe1daeFeFB3D182a
0. Before you Start
There are a few steps you have to complete before you can start the tutorial.- You will need to install Node.js and npm. If you’ve coded before, you likely have these.
- Add your Story Network Testnet wallet’s private key to
.envfile:
env
- Add your preferred RPC URL to your
.envfile. You can just use the public default one we provide:
env
- Install the dependencies:
Terminal
1. Set up your Story Config
In autils.ts file, add the following code to set up your Story Config:
- Associated docs: TypeScript SDK Setup
utils.ts
2. Tipping the Derivative IP Asset
Now create amain.ts file. We will use the payRoyaltyOnBehalf function to pay the derivative asset.
You will be paying the IP Asset with $WIP. Note that if you don’t have enough $WIP, the function will auto wrap an equivalent amount of $IP into $WIP for you. If you don’t have enough of either, it will fail.
Whitelisted Revenue TokensOnly tokens that are whitelisted by our protocol can be used as payment (“revenue”) tokens. $WIP is one of those tokens. To see that list, go here.
payRoyaltyOnBehalf function. In this case:
receiverIpIdis theipIdof the derivative (child) assetpayerIpIdiszeroAddressbecause the payer is a 3rd party (someone that thinks Mickey Mouse with a hat on him is cool), and not necessarily another IP Assettokenis the address of $WIP, which can be found hereamountis 2, since the person tipping wants to send 2 $WIP
main.ts
3. Child Claiming Due Revenue
At this point we have already finished the tutorial: we learned how to tip an IP Asset. But what if the child and parent want to claim their due revenue? The child has been paid 2 $WIP. But remember, it shares 50% of its revenue with the parent IP because of thecommercialRevenue = 50 in the license terms.
The child IP can claim its 1 $WIP by calling the claimAllRevenue function:
ancestorIpIdis theipIdwe’re claiming revenue forcurrencyTokensis an array that contains the address of $WIP, which can be found hereclaimeris the address that holds the royalty tokens associated with the child’s IP Royalty Vault. By default, they are in the IP Account, which is just theipIdof the child asset.
Claiming revenue is permissionless. Any wallet can run the claim revenue transaction for an IP.
main.ts
4. Parent Claiming Due Revenue
Continuing, the parent should be able to claim its revenue as well. In this example, the parent should be able to claim 1 $WIP since the child earned 2 $WIP and thecommercialRevShare = 50 in the license terms.
We will use the claimAllRevenue function to claim the due revenue tokens.
ancestorIpIdis theipIdof the parent (“ancestor”) assetclaimeris the address that holds the royalty tokens associated with the parent’s IP Royalty Vault. By default, they are in the IP Account, which is just theipIdof the parent assetchildIpIdswill have theipIdof the child assetroyaltyPolicieswill contain the address of the royalty policy. As explained in Royalty Module, this is eitherRoyaltyPolicyLAPorRoyaltyPolicyLRP, depending on the license terms. In this case, let’s assume the license terms specify aRoyaltyPolicyLAP. Simply go to Deployed Smart Contracts and find the correct address.currencyTokensis an array that contains the address of $WIP, which can be found here
Claiming revenue is permissionless. Any wallet can run the claim revenue transaction for an IP.
main.ts
5. Where does revenue get claimed to? Why do I not see it in my wallet? Why is it in the IP Account?
A couple of things to note here:- By default, revenue is claimed to the IP Account, not the IP owner’s wallet. This is because when an IP is created, the royalty tokens for that IP (where revenue gets claimed to) are minted to the IP Account.
-
To transfer revenue from IP Account -> IP Owner’s wallet, an IP owner can
run the
transferErc20function (it will not work if you run it for someone else’s IP obviously).main.ts -
If the IP owner (the wallet that owns the underlying IP ownership NFT) had
called
claimAllRevenuebefore, our SDK would automatically transfer the revenue to the IP owner’s wallet for convenience. -
If the IP owner wants revenue to always be claimed to their wallet and
avoid the middle step, they should transfer the royalty tokens from the IP
account to their wallet.
main.ts

