Create a Universal Profile
If you want to run the code as standalone JavaScript files within the terminal or the browser, you can open the lukso-playground
repository or use the correlated StackBlitz page.
Setupâ
To easiest way to create a Universal Profile is through the Universal Profile Browser Extension:
- install the ðĨïļ Universal Profile Browser Extension
- and âĻ create a Universal Profile
However, if you want to create a profile programmatically you should use the âïļlsp-factory.js. You can install it in your project using:
npm install @lukso/lsp-factory.js
Introductionâ
Owned Contractsâ
A Universal Profile is an owned smart contract. Ownership means that such a contract has a separate owner.
The Contract's owner is a blockchain address
that can represent anything, such as:
- one or multiple Externally Owned Accounts (EOAs),
- a multi-sig wallet, or
- another smart contract that can represent anything (a DAO, a DEX, etc...).
For more details, see EIP-173: Contract Ownership Standard
With the Ownable design pattern, a contract can be designed with functionalities that only the owner can perform. The design pattern gives the contract owner more control and privileges.
In the context of Universal Profile, reading data from the contract storage can be done by anyone, but only the owner can:
setData(...)
= add, edit or remove data from the ERC725Y storage.execute(...)
= transfer LYX to addresses, call other contracts, or create and deploy new contracts (see ERC725X executor)transferOwnership(...)
= make an address be the new owner of the Universal Profile.
In this guide, your Universal Profile's owner will be a contract called a Key Manager. The Key Manager is a smart contract that enables granting specific permissions to addresses
, so that they can interact with the Universal Profile. For example, transferring LYX on behalf of the Universal Profile.
You can implement any complex ownership structure (and fine-grained control) on top of Universal Profiles. The structure includes having a UP owned and controlled by:
- one or multiple EOAs,
- one or multiple other smart contracts, or
- a mixture of both.
For more details, see LSP6 - Key Manager Standard.
Contracts Overviewâ
The lsp-factory.js library will help us quickly deploy and set up a Universal Profile with just a few lines of code.
Under the hood, lsp-factory.js performs the following:
- Deploy the Universal Profile contracts:
- Universal Profile (UP) is the core smart contract representing a Universal Profile.
- Key Manager (KM) is the contract that acts as the owner of a Universal Profile
to enable other addresses to interact with the UP.
- Link a previously deployed Universal Receiver Delegate (URD) smart contract with the deployed UP. The URD reacts to events, such as tokens received or transferred.
- Set all the permissions for provided EOA addresses so that they can act on the UP.
The figure above is your default setup for Universal Profile. However, using a Key Manager as an owner is optional.
You can create a Universal Profile without a Key Manager (or a Universal Receiver Delegate linked to it).
Create an EOAâ
You should do this step in a temporary file.
As described in the introduction, your first need to create an EOA that will be used to control your Universal Profile.
You can easily create an EOA using the web3.eth.accounts.create()
method from web3.js.
Instructions: create a temporary file and add the code snippet below. It will generate an object that contains:
- a private key (32 bytes / 64 characters long),
- an address (20 bytes / 40 characters long), and
- some signing methods like
sign
import Web3 from 'web3';
const web3 = new Web3();
const myEOA = web3.eth.accounts.create();
console.log(myEOA);
/**
{
address: "0x...",
privateKey: "0x...",
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}
*/
See the Web3.js docs for more infos on creating an EOA
Get some LYXtâ
After creating an EOA that will control your Universal Profile, you will need to fund uour address with some test LYXt (the native cryptocurrency of the LUKSO Testnet blockchain). You can obtain some free test LYX via the Testnet Faucet.
Instructions: visit the faucet website, and follow the instructions to request LYXt.
âĄïļ LUKSO Testnet Faucet Website
Look up your address balance in the LUKSO Testnet Block Explorer to ensure you have received your test LYX.
Create your Universal Profileâ
You should do the rest of this tutorial in a new file.
Now that you have created your EOA, you are ready to create your first Universal Profile.
Load your EOAâ
Load your EOA in your main JS file so that you can use it to deploy your Universal Profile.
Instructions: import the private key that you created
import Web3 from 'web3';
const web3 = new Web3();
const PRIVATE_KEY = '0x...'; // your EOA private key
const myEOA = web3.eth.accounts.privateKeyToAccount(PRIVATE_KEY);
/**
{
address: "0x...",
privateKey: "0x...",
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}
*/
Your private key is what enables you to control your EOA. Therefore, it should NEVER be exposed.
For simplicity in this tutorial, we load the EOA using a hardcoded private key (as a literal string).
However, your private key should never be hardcoded in your code.
â ïļ ALWAYS ensure that your private key is stored securely and never exposed.
Setup the lsp-factory.jsâ
Import and set up your lsp-factory.js tool. It will give you access to a .deploy(...)
method that you will use to create your Universal Profile.
import { LSPFactory } from '@lukso/lsp-factory.js';
const PRIVATE_KEY = '0x...'; // add the private key of your EOA here
const myEOA = web3.eth.accounts.privateKeyToAccount(PRIVATE_KEY);
// initialize the LSPFactory with the Testnet chain RPC endpoint, chainId and your EOA's private key which will deploy the UP smart contracts
const lspFactory = new LSPFactory('https://rpc.testnet.lukso.network', {
deployKey: PRIVATE_KEY,
chainId: 4201,
});