Completed Code
Follow the completed code all the way through.
Prerequisites
There are a few steps you have to complete before you can start the tutorial.- Complete the Setup Your Own Project
Before We Start
There are two scenarios:- You already have a custom ERC-721 NFT contract and can mint from it
- You want to create an SPG (Periphery) NFT contract to do minting for you
Scenario #1: You already have a custom ERC-721 NFT contract and can mint from it
If you already have an NFT minted, or you want to register IP using a custom-built ERC-721 contract, this is the section for you. As you can see below, the registration process is relatively straightforward. We useSimpleNFT
as an example, but you can replace it with your own ERC-721 contract.
All you have to do is call register
on the IP Asset Registry with:
chainid
- you can simply useblock.chainid
tokenContract
- the address of your NFT collectiontokenId
- your NFT’s ID
test/0_IPARegistrar.t.sol
to see it work and verify the results:
Contract AddressesWe have filled in the addresses from the Story contracts for you. However you can also find the addresses for them here: Deployed Smart ContractsYou can view the
SimpleNFT
contract we’re using to test here.You can view the
SimpleNFT
contract we’re using to test here.test/0_IPARegistrar.t.sol
Scenario #2: You want to create an SPG NFT contract to do minting for you
If you don’t have your own custom NFT contract, this is the section for you. To achieve this, we will be using the SPG, which is a utility contract that allows us to combine multiple transactions into one. In this case, we’ll be using the SPG’smintAndRegisterIp
function which combines both minting an NFT and registering it as an IP Asset.
In order to use mintAndRegisterIp
, we first have to create a new SPGNFT
collection. We can do this simply by calling createCollection
on the StoryProtocolGateway
contract. Or, if you want to create your own SPGNFT
for some reason, you can implement the ISPGNFT contract interface. Follow the example below to see example parameters you can use to initialize a new SPGNFT.
Once you have your own SPGNFT, all you have to do is call mintAndRegisterIp
with:
spgNftContract
- the address of your SPGNFT contractrecipient
- the address of who will receive the NFT and thus be the owner of the newly registered IP. Note: remember that registering IP on Story is permissionless, so you can register an IP for someone else (by paying for the transaction) yet they can still be the owner of that IP Asset.ipMetadata
- the metadata associated with your NFT & IP. See this section to better understand setting NFT & IP metadata.
- Run
touch test/0_IPARegistrar.t.sol
to create a test file undertest/0_IPARegistrar.t.sol
. Then, paste in the following code:
Contract AddressesWe have filled in the addresses from the Story contracts for you. However you can also find the addresses for them here: Deployed Smart Contracts
test/0_IPARegistrar.t.sol
Run the Test and Verify the Results
-
Run
forge build
. If everything is successful, the command should successfully compile. - Now run the test by executing the following command:
Add License Terms to IP
Congratulations, you registered an IP!Completed Code
Follow the completed code all the way through.