Standard Detection
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.
You can also use the ð ERC725 Inspect Tool to fetch and check standards of smart contract addresses within the browser.
âĻïļ The full code of this example can be found in the ðū lukso-playground repository.
Setupâ
The following code snippets require to install a few libraries.
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 (= metadata) 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.
import { ERC725 } from '@erc725/erc725.js';
import lsp3ProfileSchema from '@erc725/erc725.js/schemas/LSP3ProfileMetadata.json';
const erc725js = new ERC725(lsp3ProfileSchema, '<myProfileAddress>', 'https://4201.rpc.thirdweb.com',
{
ipfsGateway: 'https://api.universalprofile.cloud/ipfs',
},
);
// Fetch the supported storage standard of LSP3
const isLSP3 = await erc725js.getData('SupportedStandards:LSP3Profile');
// Verify if the standard is supported (value !== null)
console.log(isLSP3);
Example for detecting LSP9Vault data keys
import { ERC725 } from '@erc725/erc725.js';
import lsp9VaultSchema from '@erc725/erc725.js/schemas/LSP9Vault.json';
const erc725js = new ERC725(
lsp9VaultSchema,
'0x9139def55c73c12bcda9c44f12326686e3948634',
'https://4201.rpc.thirdweb.com',
{
ipfsGateway: 'https://api.universalprofile.cloud/ipfs',
},
);
// Fetch the supported storage standard of LSP9
let isLSP9 = await erc725js.getData('SupportedStandards:LSP9Vault');
// Verify if the standard is supported (value !== null)
console.log(isLSP9);
Example for detecting LSP4DigitalAsset metadata data keys
import { ERC725 } from '@erc725/erc725.js';
import lsp3ProfileSchema from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json';
const erc725js = new ERC725(
lsp3ProfileSchema,
'0x6395b330F063F96579aA8F7b59f2584fb9b6c3a5',
'https://4201.rpc.thirdweb.com',
{
ipfsGateway: 'https://api.universalprofile.cloud/ipfs',
},
);
// Fetch the supported storage standard of LSP4
let isLSP4 = await erc725js.getData('SupportedStandards:LSP4DigitalAsset');
// Verify if the standard is supported (value !== null)
console.log(isLSP4);
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.
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.