Integrate Curated Lists

On chain and off chain

To refer to the contents of a curated list in your smart contract you can simply rely on all the methods available under LSP8IdentifiableDigitialAssetarrow-up-right and its Enumerablearrow-up-right extension, with the target address being the curated lists' address on the blockchain.

Entry ids in a curated list are stored as bytes32 so in order to check if a particular blockchain address is an entry within a curated you'd first pad the address with 0s and then rely on the getOperatorsOf(tokenId) methodarrow-up-right.

If you want to read all the addresses of the entries in a list, you can fetch the totalSupply() and then using that result and the tokenAt(uint256 index) methodarrow-up-right, fetch the address for the full set.

For some possible usecases relying on curated lists please refer to: Curated Lists & Their Use Cases.

Solidity Example

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

// Example Solidity contract to integrate with a curated list
import {LSP8Enumerable} from "@lukso/lsp-smart-contracts/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol";

contract IntegrateCuratedList {
    function isAddressInCuratedList(address curatedListAddress, address targetAddress) internal view returns (bool) {
        // Pad the target address with zeros to create the token ID
        bytes32 tokenId = bytes32(uint256(uint160(targetAddress)));
        
        // Instantiate the curated list contract instance
        ILSP8IdentifiableDigitalAsset curatedList = ILSP8IdentifiableDigitalAsset(curatedListAddress);
        
        // Check if the token exists
        try curatedList.tokenOwnerOf(tokenId) {
            return true;
        } catch (bytes memory) {
            return false;
        }
    }

    function getAllEntries(address curatedListAddress) public view returns (address[] memory) {
        // Instantiate the curated list contract instance
        LSP8Enumerable curatedList = LSP8Enumerable(curatedListAddress);
        
        // Get total number of entries in the list
        uint256 totalEntries = curatedList.totalSupply();
        
        // Initialize an array to hold all addresses
        address[] memory entries = new address[](totalEntries);
        
        // Fetch all addresses using tokenAt method
        for (uint256 i = 0; i < totalEntries; i++) {
            bytes32 tokenId = curatedList.tokenAt(i);
            entries[i] = address(uint160(uint256(tokenId)));
        }
        return entries;
    }
}

JS/Typescript Example

Last updated