Standard Detection
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.
Use the π ERC725 Inspect Tool to check standards interfaces and metadata of smart contract addresses easily.
β¨οΈ 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.
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β
- ethers
- web3
- erc725.js
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
import UniversalProfile from '@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json';
import { SupportedStandards } from '@lukso/lsp-smart-contracts';
import Web3 from 'web3';
// Connect to the LUKSO network
const web3 = new Web3('https://rpc.testnet.lukso.network');
// Create an instance of the Universal Profile
const myUPContract = new web3.eth.Contract(
'<myContractAddress>',
UniversalProfile.abi,
);
const result = await myUPContract.methods
.getData(SupportedStandards.LSP3Profile.key)
.call();
// Verify if the metadata standard is supported
const supportsLSP3Metadata = result == SupportedStandards.LSP3Profile.value;
console.log(supportsLSP3Metadata); // true or false
import lsp3ProfileSchema from '@erc725/erc725.js/schemas/LSP3ProfileMetadata.json';
import { SupportedStandards } from '@lukso/lsp-smart-contracts';
import { ERC725 } from '@erc725/erc725.js';
const erc725js = new ERC725(
'<myContractAddress>', // Universal Profile contract address
lsp3ProfileSchema,
'https://rpc.testnet.lukso.network',
);
const result = await erc725js.getData('SupportedStandards:LSP3Profile');
// 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β
- ethers
- web3
- erc725.js
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
import lsp4Schema from '@lukso/lsp-smart-contracts/artifacts/LSP4DigitalAssetMetadata.json';
import { SupportedStandards } from '@lukso/lsp-smart-contracts';
import Web3 from 'web3';
// Connect to the LUKSO network
const web3 = new Web3('https://rpc.testnet.lukso.network');
// Create an instance of the Universal Profile
const myUPContract = new web3.eth.Contract(
'<myContractAddress>',
lsp4Schema.abi,
);
const result = await myUPContract.methods
.getData(SupportedStandards.lsp4DigitalAsset.key)
.call();
// Verify if the metadata standard is supported
const supportsLSP4DigitalAsset =
result == SupportedStandards.LSP4DigitalAsset.value;
console.log(supportsLSP4DigitalAsset); // true or false
import lsp4Schema from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json';
import { SupportedStandards } from '@lukso/lsp-smart-contracts';
import { ERC725 } from '@erc725/erc725.js';
const erc725js = new ERC725(
'<myContractAddress>', // Digital Asset contract address
lsp4Schema,
'https://rpc.testnet.lukso.network',
);
let result = await erc725js.getData('SupportedStandards:LSP4DigitalAsset');
// Verify if the metadata standard is supported
const supportsLSP4Metadata =
result == SupportedStandards.LSP4DigitalAsset.value;
console.log(supportsLSP4Metadata); // true or false
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.
A Universal Profile is a contract based on LSP0 - ERC725Account. Therefore, the contract MUST implement the functions defined in the ERC725Account interface.
- ethers
- web3
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),
);
import UniversalProfile from '@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json';
import { INTERFACE_IDS } from '@lukso/lsp-smart-contracts/constants';
import Web3 from 'web3';
// Connect to the LUKSO 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,
'<myContractAddress>',
);
const LSP0_INTERFACE_ID = INTERFACE_IDS.LSP0ERC725Account;
console.log(
// true or false
await myUPContract.methods.supportsInterface(LSP0_INTERFACE_ID).call(),
);
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:
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
See ERC165 - Standard Interface Detection for more details.