Using an Example
Combine all of our tutorials together in a practical example.
Completed Code
See the completed code.
Video Walkthrough
Check out a video walkthrough of this tutorial!
Writing the Smart Contract
Now that we have walked through each of the individual steps, let’s try to write, deploy, and verify our own smart contract.
Register IPA, Register License Terms, and Attach to IPA
In this first section, we will combine a few of the tutorials into one. We will create a function named mintAndRegisterAndCreateTermsAndAttach
that allows you to mint & register a new IP Asset, register new License Terms, and attach those terms to an IP Asset. It will also accept a receiver
field to be the owner of the new IP Asset.
Prerequisites
- Complete Register an IP Asset
- Complete Register License Terms
- Complete Attach Terms to an IPA
Writing our Contract
Create a new file under ./src/Example.sol
and paste the following:
Contract Addresses
In order to get the contract addresses to pass in the constructor, go to Deployed Smart Contracts.
Mint a License Token and Register as Derivative
In this next section, we will combine a few of the later tutorials into one. We will create a function named mintLicenseTokenAndRegisterDerivative
that allows a potentially different user to register their own “child” (derivative) IP Asset, mint a License Token from the “parent” (root) IP Asset, and register their child IPA as a derivative of the parent IPA. It will accept a few parameters:
parentIpId
: theipId
of the parent IPAlicenseTermsId
: the id of the License Terms you want to mint a License Token forreceiver
: the owner of the child IPA
Prerequisites
- Complete Mint a License Token
- Complete Register a Derivative
Writing our Contract
In your Example.sol
contract, add the following function at the bottom:
Testing our Contract
Create another new file under test/Example.t.sol
and paste the following:
Run forge build
. If everything is successful, the command should successfully compile.
To test this out, simply run the following command:
Deploy & Verify the Example Contract
The --constructor-args
come from Deployed Smart Contracts.
If everything worked correctly, you should see something like Deployed to: 0xfb0923D531C1ca54AB9ee10CB8364b23d0C7F47d
in the console. Paste that address into the explorer and see your verified contract!