Skip to main content

Standard Detection

caution

The interfaceId and the SupportedStandards:{StandardName} data key is not the most secure way to check for a standard, as they could be set manually.

There are two types of LSP standards:

Interface and metadata standards

These two standards types are fundamental for interacting with smart contracts on the LUKSO blockchain.

The Interface Standard defines the functions that can be called on a smart contract and their expected parameters. On the other hand, Metadata Standard informs about the data set by default on the contract and which data keys to query to retrieve such data.

Interface Detection

Tip

See the page Contracts Implementation > Interface IDs for a complete list of current interfaceId fields.

This section covers how to detect if a contract implements a specific interface.

We can verify if a contract implements a specific set of functions (= an interface) using the function supportsInterface(interfaceId), passing the bytes4 interfaceId as a parameter.

Calling this function will return TRUE if the contract implements this specific interfaceId, FALSE otherwise.

Interface Example

A Universal Profile is a contract based on ERC725Account(LSP0). Therefore, the contract SHOULD implement the functions defined in the ERC725Account interface.

const UniversalProfile = require("@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json");
const Web3 = require("web3");

// Connect to the LUKSO L14 network
const web3 = new Web3("https://rpc.l14.lukso.network");

// Create an instance of the Universal Profile
const myUPContract = new web3.eth.Contract(UniversalProfile.abi, "<contract-address>");

const ERC725AccountInterfaceId = '0x63cb749b';
await myUPContract.methods.supportsInterface(ERC725AccountInterfaceId).call();
> TRUE or FALSE
info

Metadata Detection

Tip

The erc725.js GitHub repository lists all the SupportedStandards:{StandardName} data keys under each ERC725Y JSON Schema.

This section covers how to detect if a contract contains a specific set of ERC725Y in its storage.

We can verify if a contract contains a specific set of ERC725 keys (= metadata) by checking the value stored under the key SupportedStandards:{StandardName} in the contract storage, via the function getData(SupportedStandards:{StandardName}).

Calling this function will return a specific bytes4 value (defined in the Metadata Standard) if the contract has some metadata keys set by default. Otherwise, it will return an empty value.

Metadata Example

An LSP7DigitalAsset is a contract that contains ERC725Y Data keys defined in LSP4 - Digital Asset Metadata. Therefore, the contract SHOULD have the following ERC725Y Data keys set by default: LSP4TokenName, LSP4TokenSymbol, LSP4Metadata, LSP4CreatorsMap:<address> and LSP4Creators[].

const LSP7DigitalAsset = require('@lukso/lsp-smart-contracts/artifacts/LSP7DigitalAsset.json');
const Web3 = require('web3');

// Connect to the LUKSO L14 network
const web3 = new Web3('https://rpc.l14.lukso.network');

// Create an instance of the LSP7 Token
const myTokenContract = new web3.eth.Contract(LSP7DigitalAsset.abi, '<contract-address>');

const SupportedStandards_LSP4 = '0xeafec4d89fa9619884b60000a4d96624a38f7ac2d8d9a604ecf07c12c77e480c';
await myTokenContract.methods["getData(bytes32[])"]([SupportedStandards_LSP4DigitalAsset]).call();
> 0xa4d96624; // valid result according to LSP4