Getting Started
The @lukso/lsp-factory.js
package allows simple deployments of ERC725-UniversalProfiles, LSP7-DigitalAssets, and LSP8-IdentifiableDigitalAssets.
Installation
npm install @lukso/lsp-factory.js
Instantiation
import { LSPFactory } from '@lukso/lsp-factory.js';
const provider = 'https://rpc.testnet.lukso.network';
const lspFactory = new LSPFactory(provider, {
deployKey: '0x...', // Private key of the account which will deploy smart contracts
chainId: 4201,
});
Using LSPFactory in a dApp
If used in the browser on a dApp's page, pass the ethereum object as the provider parameter to connect to a browser extension like the UniversalProfile browser extension or MetaMask. The browser extension will prompt users to sign the transactions as the LSPFactory deploys the smart contracts.
await ethereum.request({ method: 'eth_requestAccounts', params: [] });
const lspFactory = new LSPFactory(ethereum, {
chainId: 4201,
});
Usage
Deploying a Universal Profile is as simple as running:
const myContracts = await lspFactory.UniversalProfile.deploy({
controllerAddresses: ['0x...'], // Account addresses which will control the UP
lsp3Profile: myLSP3MetaData,
});
The key lsp3Profile
contains the LSP3 Metadata of your Universal Profile. This is the "face" of your Universal Profile and contains all the public information people will see when they view your UP like your name, description and profile image.
const myLSP3MetaData = {
name: 'My Universal Profile',
description: 'My cool Universal Profile',
profileImage: [
{
width: 500,
height: 500,
verification: {
method: 'keccak256(bytes)',
// bytes32 hex string of the image hash
data: '0xfdafad027ecfe57eb4ad047b938805d1dec209d6e9f960fc320d7b9b11cbed14',
},
url: 'ipfs://QmPLqMFHxiUgYAom3Zg4SiwoxDaFcZpHXpCmiDzxrtjSGp',
},
],
backgroundImage: [
{
width: 500,
height: 500,
verification: {
method: 'keccak256(bytes)',
// bytes32 hex string of the image hash
data: '0xfdafad027ecfe57eb4ad047b938805d1dec209d6e9f960fc320d7b9b11cbed14',
},
url: 'ipfs://QmPLqMFHxiUgYAom3Zg4SiwoxDaFcZpHXpCmiDzxrtjSGp',
},
],
tags: ['public profile', 'creator'],
links: [
{
title: 'My Website',
url: 'www.my-website.com',
},
],
...
};
When deploying your Universal Profile, your LSP3 data will be automatically uploaded to IPFS.
If you already have LSP3 data uploaded, then you can pass an IPFS URL:
const myLSP3MetaData = 'ipfs://QmPzUfdKhY6vfcTNDnitwKnnpm5GqjYSmw9todNVmi4bqy';
To create a anonymous Universal Profile, omit the lsp3Profile
value.
Anonymous profiles can also be useful if you wish to create the LSP3 metadata later.
You can now continue using your UP address within the dApp:
const myUPAddress = myContracts.LSP0ERC725Account.address;
Options
When instantiating LSPFactory options can be passed to specify parameters such as chainId
and ipfsGateway
.
const lspFactory = new LSPFactory('https://rpc.testnet.lukso.network', {
deployKey: '0x...',
chainId: 4201,
ipfsGateway: 'https://ipfs.infura.io:5001',
});
Deploy Key
deployKey
is the private key which should sign the transactions sent by LSPFactory. This account must have enough gas to carry out the transactions.
If no value is set here, LSPFactory will attempt to sign transactions via a browser extension.
Chain Id
chainId
is used to specify the network that LSPFactory is interacting with. The provided chainId
will be used to determine which base contracts to use when using proxy deployment. Previously deployed base contract addresses are stored in the versions file and accessed using the provided chainId. Defaults to 4201 (LUKSO Testnet).
IPFS Gateway
ipfsGateway
is used to specify the IPFS node which should be interacted with for uploading and retrieving metadata. ipfsGateway
can be either a URL string or an object as defined by the IPFS-HTTP Client library which is used internally to interact with the IPFS node.
const lspFactory = new LSPFactory('https://rpc.testnet.lukso.network', {
deployKey: '0x...',
chainId: 4201,
ipfsGateway: {
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https',
},
});