Skip to main content

Create a Vault

Disclaimer

This guide might contain outdated information and will be updated soon.

This guide will teach you how to deploy an LSP9Vault contract. This contract can be used to hold assets such as tokens and NFTs. Also can be used with a UniversalProfile and a KeyManager to restrict some addresses (protocols, friends, etc..) to execute and setData on it, instead of setting or executing directly on the profile.

Guide - How to create an LSP9Vault

Deploy an LSP9Vault contract​

To start with this guide you will need the following things:

  • The private key of your account, in order to send the transaction.
  • The address of a Universal Profile

Make sure you have the following dependencies installed before beginning this tutorial:

Install the dependencies
npm install web3 @lukso/lsp-smart-contracts

Step 1 - Setup imports and constants​​

For the imports, we will need the LSP9vault contract ABI and bytecode in order to deploy a LSP9 Vault.
For the constants we will need the private key and the address of the vault receiver.

Imports & Constants
import LSP9Vault from '@lukso/lsp-smart-contracts/artifacts/LSP9Vault.json';
import Web3 from 'web3';

const web3 = new Web3('https://rpc.testnet.lukso.network');
const vaultOwner = '0x...'; // The address that will be the vault owner

// initialize your EOA
const privateKey = '0x...';
const myEOA = web3.eth.accounts.wallet.add(privateKey);

Step 2 - Instantiate contracts​

Create instance for LSP9Vault, that is needed in order to deploy the contract.

Contract instance
// create an instance of the LSP9Vault contract
let myVault = new web3.eth.Contract(LSP9Vault.abi);

Step 3 - Send transaction​

Finally send the contract deployment transaction.

Sending contract deployment transaction
// deploy the vault contract
await myVault
.deploy({
data: LSP9Vault.bytecode,
arguments: [vaultOwner],
})
.send({
from: myEOA.address,
gas: 5_000_000,
gasPrice: '1000000000',
});

Final Code​

caution

You need to have LYXt in your EOA in order to pay for the transaction fees. Visit the ➑️ LUKSO Testnet Faucet Website to get some LYXt.

Deploying the vault
import LSP9Vault from '@lukso/lsp-smart-contracts/artifacts/LSP9Vault.json';
import Web3 from 'web3';

const web3 = new Web3('https://rpc.testnet.lukso.network');
const vaultOwner = '0x...'; // The address that will be the vault owner

// initialize your EOA
const privateKey = '0x...';
const myEOA = web3.eth.accounts.wallet.add(privateKey);

// create an instance of the LSP9Vault contract
let myVault = new web3.eth.Contract(LSP9Vault.abi);

// deploy the vault contract
await myVault
.deploy({
data: LSP9Vault.bytecode,
arguments: [vaultOwner],
})
.send({
from: myEOA.address,
gas: 5_000_000,
gasPrice: '1000000000',
});