Read Universal Profile Data
The full code of this example can be found in the ðū lukso-playground repository.
The explorer on ðŪ universalprofile.cloud indexes all deployed Universal Profiles on the LUKSO network. You can try out the following examples with any Universal Profile address.
Setupâ
To easily interact with a profile you should use the âïļ erc725.js library. It is able to fetch and encode profile and contract data easily. You can install it in your project using:
npm install @erc725/erc725.js
Get all profile data keysâ
ð You can inspect a profile smart contract (or any ERC725 contract) using ð ERC725 Inspect to see all its ðïļ ERC725Y data keys.
LSP3 - Profile Metadata describes the data in the Universal Profile contract's ERC725Y data storage. You can get the content of these data keys directly using the âïļ erc725.js library. ð
SupportedStandards:LSP3Profile
verifies that the ERC725Y contract contains LSP3Profile data keysLSP3Profile
contains the JSON file with profile descriptions and imagesLSP12IssuedAssets[]
contains assets the profile issuedLSP5ReceivedAssets[]
contains assets the profile receivedLSP1UniversalReceiverDelegate
contains the address of the Universal Receiver Delegate smart contract
To read the profile data you simply instantiate the âïļ erc725.js library with your profile address, an RPC provider (web3
, ethereum
, ethers
) or plain RPC URL, and an IPFS gateway. You can find RPC URLs for LUKSO networks on the network pages: mainnet / testnet.
The getData()
function allows you to get all data keys that are stored on the profile smart contract and in your provided JSON schema.
- JavaScript
- TypeScript
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',
},
);
// Get all profile data keys of the smart contract
const profileData = await erc725js.getData();
console.log(profileData);
import { ERC725, ERC725JSONSchema } from '@erc725/erc725.js';
import lsp3ProfileSchema from '@erc725/erc725.js/schemas/LSP3ProfileMetadata.json';
const erc725js = new ERC725(lsp3ProfileSchema as ERC725JSONSchema[], '<myProfileAddress>', 'https://4201.rpc.thirdweb.com',
{
ipfsGateway: 'https://api.universalprofile.cloud/ipfs',
},
);
// Get all profile data keys of the smart contract
const profileData = await erc725js.getData();
console.log(profileData);
You can give it a try with this profile address: <myProfileAddress> = 0xE1F684655e4e688CCF72d88F028c62EC3B1046CC
.
Show result
[
{
key: '0xeafec4d89fa9619884b600005ef83ad9559033e6e941db7d7c495acdce616347',
name: 'SupportedStandards:LSP3Profile',
value: '0x5ef83ad9',
},
{
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
name: 'LSP3Profile',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x9b54d921f8365353667cabc331aa0c1dd42f173a6b7d871f7d94ac2cf226eafa',
url: 'ipfs://QmaXQSZFoUPM43kND6EUPSnJF7NjpkW9LwW6J9vRki5QDh',
},
},
{
key: '0x7c8c3416d6cda87cd42c71ea1843df28ac4850354f988d55ee2eaa47b6dc05cd',
name: 'LSP12IssuedAssets[]',
value: [],
},
{
key: '0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b',
name: 'LSP5ReceivedAssets[]',
value: [
'0x5a44c7c0E47d1BeCEF166874Cd0b1be8f4090f64',
'0x303aE9B19ee9B6FDa8c710b7F74b0582bbCC7b81',
'0x2Bc3bfFf67094B4416623bDe626fd5f904b590d1',
'0x48e37a167A3eE426389dc6E1Dc2d440E86C3737F',
'0xDB9183ddA773285d5A4C5b1067A78c9F64Fb26E6',
'0x778b47Bd998A5D0cc645Ff0c548096ea50628C83',
],
},
{
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
name: 'LSP1UniversalReceiverDelegate',
value: '0x0000000000F49F9818D746b4b999A9E449F675bb',
},
];
The âïļ erc725.js library works with ERC725Y JSON schemas. These schemas are JSON structures that tell developers and programs how to decode and encode ðïļ ERC725Y data keys. You need to load the required schemas of the data keys you want to fetch when initializing the ERC725
class. The most common schemas are available in erc725.js.
You can also create and load your own ERC725Y JSON schemas if you want to add custom data keys to the profile.
Fetch the Profile Metadataâ
If you only need the contents of the profile data JSON file, you can use fetchData('LSP3Profile')
. This will download the JSON file and verify its hash automatically.
// ...
// Download and verify the profile metadata JSON file
const profileMetaData = await erc725js.fetchData('LSP3Profile');
console.log(profileMetaData);
Show result
{
"key": "0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5",
"name": "LSP3Profile",
"value": {
"LSP3Profile": {
"name": "johann",
"description": "I'm a 40 y-old dad of 3. Technology enthusiast, skater, guitarist but mostly curious.",
"tags": [
"profile"
],
"links": [
{
"title": "...",
"url": "..."
},
...
],
"profileImage": [
{
"width": 1512,
"height": 1998,
"hashFunction": "keccak256(bytes)",
"hash": "0x...",
"url": "ipfs://..."
},
...
],
"backgroundImage": [
{
"width": 1512,
"height": 1998,
"hashFunction": "keccak256(bytes)",
"hash": "0x...",
"url": "ipfs://..."
},
...
]
}
}
}
The getData(...)
function only retrieves the data keys values from the smart contract. In comparison, fetchData(...)
will download and decode the content of VerifiableURI
.
Fetch Assets and Universal Receiverâ
Instead of using the LSP3Profile
key, you can also use other data keys like LSP12IssuedAssets[]
, LSP5ReceivedAssets[]
, or LSP1UniversalReceiverDelegate
, as described in the following example:
// ...
// Fetch all of the profile's issued assets
const issuedAssetsDataKey = await erc725js.fetchData('LSP12IssuedAssets[]');
console.log(issuedAssetsDataKey);
// Fetch all owned assets of the profile
const receivedAssetsDataKey = await erc725js.fetchData('LSP5ReceivedAssets[]');
console.log(receivedAssetsDataKey);
// Fetch the profile's universal receiver
const universalReceiverDataKey = await erc725js.fetchData('LSP1UniversalReceiverDelegate');
console.log(universalReceiverDataKey);
Show result
// Issued Assets (empty, no current assets)
{
key: '0x7c8c3416d6cda87cd42c71ea1843df28ac4850354f988d55ee2eaa47b6dc05cd',
name: 'LSP12IssuedAssets[]',
value: []
}
// Owned Assets (Six individual assets)
{
key: '0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b',
name: 'LSP5ReceivedAssets[]',
value: [
'0x5a44c7c0E47d1BeCEF166874Cd0b1be8f4090f64',
'0x303aE9B19ee9B6FDa8c710b7F74b0582bbCC7b81',
'0x2Bc3bfFf67094B4416623bDe626fd5f904b590d1',
'0x48e37a167A3eE426389dc6E1Dc2d440E86C3737F',
'0xDB9183ddA773285d5A4C5b1067A78c9F64Fb26E6',
'0x778b47Bd998A5D0cc645Ff0c548096ea50628C83'
]
}
// Universal Receiver Delegate (0x0...75bb)
{
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
name: 'LSP1UniversalReceiverDelegate',
value: '0x0000000000F49F9818D746b4b999A9E449F675bb'
}