Skip to content

lukso-network/tools-lsp-factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

610 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@lukso/lsp-factory.js

Helper library to allow simple deployments of Universal Profiles, LSP7 Digital Assets, and LSP8 Identifiable Digital Assets on LUKSO.

NPM version Tests Passing

Issues GitHub pull requests

For more information see the LUKSO Documentation.

Supported Networks

This library deploys contracts via LSP23LinkedContractsFactory, which is deployed at the same address on all supported chains via the Nick Factory for deterministic addresses:

LSP23 Factory Address: 0x2300000A84D25dF63081feAa37ba6b62C4c89a30

Network Chain ID
LUKSO Mainnet 42
LUKSO Testnet 4201
Ethereum Mainnet 1
BASE 8453

All base contract implementations (ERC725Account, KeyManager, UniversalReceiverDelegate, LSP7, LSP8) are also deployed at the same addresses across chains via the Nick Factory.

Install

npm install @lukso/lsp-factory.js

Setup

@lukso/lsp-factory.js v4 uses viem for blockchain interactions. You need a PublicClient (for reading) and a WalletClient (for signing transactions).

import { createPublicClient, createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { luksoTestnet } from 'viem/chains';
import { LSPFactory } from '@lukso/lsp-factory.js';

const account = privateKeyToAccount('0x...');

const publicClient = createPublicClient({
  chain: luksoTestnet,
  transport: http(),
});

const walletClient = createWalletClient({
  account,
  chain: luksoTestnet,
  transport: http(),
});

const factory = new LSPFactory(publicClient, walletClient);

Usage

Deploying a Universal Profile

Deploys a Universal Profile (LSP0) and KeyManager (LSP6) atomically via LSP23LinkedContractsFactory, then configures controller permissions and a Universal Receiver Delegate.

const contracts = await factory.UniversalProfile.deploy({
  controllerAddresses: ['0x...'], // Addresses that will control the UP
});

console.log('UP Address:', contracts.LSP0ERC725Account.address);
console.log('KeyManager Address:', contracts.LSP6KeyManager.address);

With LSP3 metadata and a deterministic salt

const contracts = await factory.UniversalProfile.deploy(
  {
    controllerAddresses: ['0x...'],
    lsp3DataValue: '0x...', // Pre-encoded LSP3Profile data (VerifiableURI)
  },
  {
    salt: '0x...', // bytes32 salt for deterministic address generation
  }
);

With custom controller permissions

const contracts = await factory.UniversalProfile.deploy({
  controllerAddresses: [
    '0xFullPermissionsAddress', // Gets ALL_PERMISSIONS by default
    {
      address: '0xLimitedAddress',
      permissions: '0x0000000000000000000000000000000000000000000000000000000000000010',
    },
  ],
});

Pre-computing Addresses

Compute the UP and KeyManager addresses before deploying:

const { upAddress, keyManagerAddress } = await factory.UniversalProfile.computeAddress(
  { controllerAddresses: ['0x...'] },
  { salt: '0x...' } // Use the same salt you will deploy with
);

Deploying an LSP7 Digital Asset

Deploys an LSP7 Digital Asset (fungible token) as a minimal proxy:

const contracts = await factory.LSP7DigitalAsset.deploy({
  name: 'My Token',
  symbol: 'MTK',
  controllerAddress: '0x...', // Owner of the token contract
  tokenType: 0, // 0 = Token, 1 = NFT, 2 = Collection
  isNFT: false, // Whether the token is non-divisible
});

console.log('LSP7 Address:', contracts.LSP7DigitalAsset.address);

With metadata

const contracts = await factory.LSP7DigitalAsset.deploy({
  name: 'My Token',
  symbol: 'MTK',
  controllerAddress: '0x...',
  tokenType: 0,
  isNFT: false,
  digitalAssetMetadata: {
    verification: {
      method: 'keccak256(utf8)',
      data: '0x...',
    },
    url: 'ipfs://Qm...',
  },
});

Deploying an LSP8 Identifiable Digital Asset

Deploys an LSP8 Identifiable Digital Asset (NFT) as a minimal proxy:

const contracts = await factory.LSP8IdentifiableDigitalAsset.deploy({
  name: 'My NFT Collection',
  symbol: 'MNFT',
  controllerAddress: '0x...',
  tokenType: 1, // 0 = Token, 1 = NFT, 2 = Collection
  tokenIdFormat: 1, // Token ID format (e.g., 1 = Number)
});

console.log('LSP8 Address:', contracts.LSP8IdentifiableDigitalAsset.address);

Deployment Events

All deploy methods accept an onDeployEvents callback for tracking deployment progress:

const contracts = await factory.UniversalProfile.deploy(
  { controllerAddresses: ['0x...'] },
  {
    onDeployEvents: {
      next: (event) => {
        console.log(event.status, event.contractName, event.functionName);
      },
      error: (error) => {
        console.error('Deployment error:', error);
      },
      complete: (deployedContracts) => {
        console.log('Deployment complete:', deployedContracts);
      },
    },
  }
);

Development

Install dependencies

npm install

Lint

npm run lint
npm run lint:fix  # auto-fix

Build

npm run build

Test

npm test

Contributing

Please check CONTRIBUTING.

License

lsp-factory.js is Apache 2.0 licensed.

About

Easy deployments of LSP standard Universal Profile and Digital Asset smart contracts

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors