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 used to interact with smart contracts on the LUKSO blockchain.

Standard TypeDescriptionExamples
Interface StandardsStandardize a set of functions.
Defines the functions that can be called on a smart contract and their expected parameters
LSP0-ERC725Account
LSP6-KeyManager
LSP7-DigitalAsset
Metadata StandardsStandardize a set of ERC725Y data keys.
Informs about the data set by default on the contract and which data keys to query to retrieve such data
LSP3-UniversalProfile-Metadata
LSP4-DigitalAsset-Metadata
LSP10ReceivedVaults

Interface and metadata standards

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.

import UniversalProfile from '@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json';
import Web3 from 'web3';

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

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

const lsp0InterfaceId = '0x3e89ad98';
await myUPContract.methods.supportsInterface(lsp0InterfaceId).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[].

import LSP7DigitalAsset from '@lukso/lsp-smart-contracts/artifacts/LSP7DigitalAsset.json';
import Web3 from 'web3';

// Connect to the LUKSO L14 network
const web3 = new Web3('https://rpc.testnet.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(SupportedStandards_LSP4).call();
// 0xa4d96624 -> valid result according to LSP4

Further information