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.

tip

Use the πŸ”Ž ERC725 Inspect Tool to check standards interfaces and metadata of smart contract addresses easily.

info

⌨️ The full code of this example can be found in the πŸ‘Ύ lukso-playground repository.

If you want to ensure that LSP standards are implemented and working correctly before letting your application interact with smart contracts, you can check their supported ERC725 storage keys and interfaces.

Setup​

The following code snippets require the following libraries to be installed:

npm install web3 @erc725/erc725.js @lukso/lsp-smart-contracts

Metadata Detection​

You can verify if a contract contains a specific set of ERC725Y keys by checking the value stored under the ERC725Y storage key SupportedStandards:{StandardName} using the erc725.js library.

Example

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[].

Similar to the Read Profile Data Guide, you can use the getData() function to check if the contract has a specific metadata standard like LSP3 Profile, LSP4 Digital Asset or a LSP9 Vault.

Example 1 - Detect LSP3 Profile data keys​

import UniversalProfile from '@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json';
import { SupportedStandards } from '@lukso/lsp-smart-contracts';
import { ethers } from 'ethers';

// Connect to the LUKSO network
const provider = new ethers.JsonRpcProvider(
'https://rpc.testnet.lukso.network',
);

// Create an instance of the Universal Profile
const myUPContract = new ethers.Contract(
'<myContractAddress>',
UniversalProfile.abi,
provider,
);

const result = await myUPContract.getData(SupportedStandards.LSP3Profile.key);

// Verify if the metadata standard is supported
const supportsLSP3Metadata =
result.value == SupportedStandards.LSP3Profile.value;

console.log(supportsLSP3Metadata); // true or false

Example 2 - Detect LSP4 Digital Asset data keys​

import lsp4Schema from '@lukso/lsp-smart-contracts/artifacts/LSP4DigitalAssetMetadata.json';
import { SupportedStandards } from '@lukso/lsp-smart-contracts';
import { ethers } from 'ethers';

// Connect to the LUKSO network
const provider = new ethers.JsonRpcProvider(
'https://rpc.testnet.lukso.network',
);

// Create an instance of the Universal Profile
const myUPContract = new ethers.Contract(
'<myContractAddress>',
lsp4Schema.abi,
provider,
);

const result = await myUPContract.getData(SupportedStandards.lSP4DigitalAsset.key);

// Verify if the metadata standard is supported
const supportsLSP4DigitalAsset = result == SupportedStandards.LSP4DigitalAsset.value;

console.log(supportsLSP4DigitalAsset); // true or false
note

You can also check custom data on smart contract storage by loading your own JSON schemas.

Interface Identification​

Every LSP standard has its own interface ID (as defined by ERC-165). To verify their specific set of functions (= an interface) you can call the standardized supportsInterface(interfaceId) function, passing the bytes4 interfaceId as a parameter.

Interface Detection​

Calling this function will return true if the contract implements this specific interface ID.

Example

A Universal Profile is a contract based on LSP0 - ERC725Account. Therefore, the contract MUST implement the functions defined in the ERC725Account interface.

import UniversalProfile from '@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json';
import { INTERFACE_IDS } from '@lukso/lsp-smart-contracts/constants';
import { ethers } from 'ethers';

// Connect to the LUKSO network
const provider = new ethers.JsonRpcProvider(
'https://rpc.testnet.lukso.network',
);

// Create an instance of the Universal Profile
const myUPContract = new ethers.Contract(
'<myContractAddress>',
UniversalProfile.abi,
provider,
);

const LSP0_INTERFACE_ID = INTERFACE_IDS.LSP0ERC725Account;
console.log(
// true or false
await myUPContract.supportsInterface(LSP0_INTERFACE_ID),
);

Instead of using the interface ID from LSP0ERC725Account, you can use any of the supported IDs within the lsp-smart-contracts library to check all standards used by the LSP ecosystem:

ERC165                        ERC20
ERC223 ERC721
ERC721Metadata ERC725X
ERC725Y ERC777
ERC1155

LSP0ERC725Account LSP1UniversalReceiver
LSP6KeyManager LSP7DigitalAsset
LSP8IdentifiableDigitalAsset LSP9Vault
LSP11BasicSocialRecovery LSP14Ownable2Step
LSP17Extendable LSP17Extension
LSP20CallVerification LSP20CallVerifier
LSP25ExecuteRelayCall
Further Information