Closed doliG closed 2 years ago
@DaigaroCota @tiagofneto need help on the second point: how can I read the souvenir NFT from smart contracts ? Which method to call, and what to expect in return. Ty.
I'm not exactly sure by what you mean by "read the souvenir NFT" but I will give you some insight on how it works:
NFTGame
ERC1155 contract (in the same way the points, crates and cards are stored)UserData
struct for each user, in the lockedNFTID
fielduserdata
variable for that specific user, which returns a UserData
struct for that user, from where you can use the field lockedNFTID
NFTGame
contract (for example, getting the uri)What Tiago described is precise. Once you get the LockNFTID
you need to pass it to the functionuri()
in the contract NFTGame.sol
.
You will get in return a base64 encoded json object. To uncode it you need a package like:
https://www.npmjs.com/package/base-64
Important to note that the image property of the json object is also base64 encoded.
You can see the output of uri() by running one of the test scripts. From the hardhat package root folder:
Start a node with
yarn fork
on a terminal On a seperate terminal run:npx hardhat --network localhost test ./test/fantom/nftgame/onchain_nfts.js
You will see the output spitted out in the terminal. You can then use a public website https://www.base64decode.org/ to decode manual and see the json data structure yourself.
As a side note, I believe browsers have built-in these two functionsatob()
and btoa()
that encode and decode base64.
I did the following from Brave. However, don't know if this is universal to all browsers... or if these functions are accessible by React framework.
See figma