Fetching NFTs, Stacks and Hiro API
Explanations
Fetch all NFTs owned by user address
Stacks API URL
https://stacks-node-api.mainnet.stacks.co/extended/v1/tokens/nft/holdings?principal=SP1SCEXE6PMGPAC6B4N5P2MDKX8V4GF9QDE1FNNGJ&&asset_identifiers=SP1SCEXE6PMGPAC6B4N5P2MDKX8V4GF9QDE1FNNGJ.workshop-nfts-integration::duckJSON Response Structure
{
"limit": 50,
"offset": 0,
"total": 4,
"results": [
{
"asset_identifier": "ST28AA1PJD8615MPKKKSSX311EWY000G77SFEXXHX.my-nft::character",
"value": {
"hex": "0x0100000000000000000000000000000002",
"repr": "u2"
},
"block_height": 81902,
"tx_id": "0xb7a5d44a610d1e1ead9d8e5d34909600fe566550a9c7c63ce8c8bd585f121c89"
},
{
"asset_identifier": "ST28AA1PJD8615MPKKKSSX311EWY000G77SFEXXHX.my-nft::character",
"value": {
"hex": "0x0100000000000000000000000000000001",
"repr": "u1"
},
"block_height": 81902,
"tx_id": "0x158d69b6877120d8ea83ee94bb7a90bf9074a8c39854ce55eee0dff5599d9c45"
},
{
"asset_identifier": "ST28AA1PJD8615MPKKKSSX311EWY000G77SFEXXHX.my-nft::character",
"value": {
"hex": "0x0100000000000000000000000000000003",
"repr": "u3"
},
"block_height": 81902,
"tx_id": "0x62aeed938b57da7adc473d8017792cc13cee714e4d93fdc829c57b5aaff5b980"
},
{
"asset_identifier": "ST28AA1PJD8615MPKKKSSX311EWY000G77SFEXXHX.my-nft::character",
"value": {
"hex": "0x0100000000000000000000000000000004",
"repr": "u4"
},
"block_height": 81950,
"tx_id": "0x19300a8d2663b02e0012be879597372cf4dece9c09128cf2069ea46a98bc07ba"
}
]
}Code inserted
Function to get ids of NFTs from JSON
Function to fetch all the JSON responses from the API and get all the ids of the owned NFTs
Explanations for the `getNFTsOwned` function
Recap how the final code should look in MainMenu file
This is the branch with the changes done:
Last updated
Was this helpful?
