Note: This article was updated on Sep 20th, 2022 to use Cairo 0.10
Claiming an NFT
- Mint a NFT with metadata on this dummy ERC721 token, usable here
- Check it on Oasis
- Claim points on ex6_claim_metadata_token (2 pts)
Looking for exercise 5? Click here.
Solution
The provided dummy smart contract has two functions that would allow us to mint an NFT: mint and claim.
@external
func mint{...}(to : felt, token_id : Uint256) {
Ownable.assert_only_owner();
ERC721._mint(to, token_id);
return ();
}
@external
func claim{...}(to : felt) {
let (token_id) = next_token_id_storage.read();
let one_as_uint = Uint256(1, 0);
let (next_token_id, _) = uint256_add(one_as_uint, token_id);
next_token_id_storage.write(next_token_id);
ERC721._mint(to, token_id);
return ();
}
The function mint only allows the owner of the smart contract to mint a new NFT so it’s out of reach for us, we have to use claim. To interact with the smart contract we follow the link to Voyager (0x4fc2…) and invoke the function claim passing the address of our test account on Argent X (0x0113...).
Note: You can use Braavos as an alternative to Argent X.
Once the transaction is processed by the network, we can go to Aspect (Oasis rebrand), log in with our Argent X test account and check our newly minted NFT.
Now that we have verified that the NFT was minted and it is in our possession, we can interact with the Evaluator (0x06d2…) to verify the successful completion of exercise 6.
The Evaluator function ex6_claim_metadata_token requires to be provided with the token_id of the generated NFT. To get this token_id we need to interact one more time with the dummy NFT smart contract (0x4fc2…) and call the view function next_token_id.
Because this is the value that will be used for the next NFT to be minted, we know that our token_id is 3. We have now all the information to invoke the Evaluator (0x06d2…) function ex6_claim_metadata_token.
If everything goes well, we should have been awarded two more points on our Argent X test account on the Points Counter smart contract (0x00a0…).
Sure enough we have been awarded 2 more points on our Argent X test account. We have successfully completed exercise 6.
To continue the tutorial go to Exercise 7: Adding Metadata.