-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #637 from lukso-network/contracts-section
Move Hardhat guide as Getting Started for Contracts
- Loading branch information
Showing
7 changed files
with
134 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,120 @@ | ||
--- | ||
sidebar_label: Deploy our custom LSP7 contract | ||
sidebar_position: 3 | ||
sidebar_label: Getting Started | ||
title: Getting Started | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Deploy your contract | ||
This page will guide you through the process of: | ||
|
||
Following the previous guide (["Create a custom LSP7 contract"](./create-custom-lsp7.md)), we are now ready to deploy our contract on the LUKSO Testnet network! | ||
- setting up an [Hardhat](https://hardhat.org/) installation (using TypeScript) | ||
- adding the [`@lukso/lsp-smart-contracts`](https://www.npmjs.com/package/@lukso/lsp-smart-contracts) package (using version 0.11.0-rc.1) | ||
- creating a basic `LSP7DigitalAsset` contract | ||
- and deploying it on [LUKSO Testnet](../../networks/testnet/parameters). | ||
|
||
## Deploy the contract on LUKSO Testnet | ||
### Create Hardhat project | ||
|
||
The first thing to do is to [create a new Hardhat project](https://hardhat.org/hardhat-runner/docs/getting-started#quick-start) that will use TypeScript: | ||
|
||
```bash title="Setup new hardhat project" | ||
mkdir lukso-app | ||
cd lukso-app | ||
npx hardhat | ||
# select 'Create a TypeScript project' and | ||
# use the default value for the rest of the setup | ||
``` | ||
|
||
Once finished, you have a working Hardhat setup! | ||
|
||
### Install packages & setup tools | ||
|
||
To work in the best condition possible, we will install libraries that includes tools, helpers and the [`@lukso/lsp-smart-contracts`](https://www.npmjs.com/package/@lukso/lsp-smart-contracts) package. | ||
|
||
#### Install dependencies | ||
|
||
```bash | ||
npm i -D dotenv | ||
npm i -s @lukso/[email protected] | ||
``` | ||
|
||
#### Add a build script in your package.json | ||
|
||
Update your `package.json` with the following: | ||
|
||
```json title="package.json" | ||
"scripts": { | ||
"build": "hardhat compile --force --show-stack-traces" | ||
}, | ||
``` | ||
|
||
#### Create a .env file | ||
|
||
Create a new file at the root of your project called `.env` with the following content: | ||
|
||
:::warning | ||
|
||
The `.env` file contains sensitive values such as PRIVATE_KEY. Do not commit it to your source code repository! | ||
|
||
::: | ||
|
||
:::note | ||
|
||
We will populate the values of the `.env` file later. | ||
|
||
::: | ||
|
||
```text title=".env" | ||
PRIVATE_KEY= | ||
UP_ADDR= | ||
``` | ||
|
||
We now have a base Hardhat setup that we can use to develop and deploy our smart contracts. | ||
|
||
|
||
## Create a custom LSP7 Token contract | ||
|
||
We will now create a custom [LSP7 Digital Asset contract](../standards/nft-2.0/LSP7-Digital-Asset.md). This contract will extend [`LSP7Mintable`](./contracts/LSP7DigitalAsset/presets/LSP7Mintable.md) & [LSP7Burnable](./contracts/LSP7DigitalAsset/extensions/LSP7Burnable.md) (to allow burning tokens). We will also pre-mint 20k tokens to the owner of the contract (the deployer). | ||
To do that, delete the `Lock.sol` contract in the `contracts/` folder, then create a new file named `MyCustomToken.sol` with the following content: | ||
|
||
```solidity title="contracts/MyCustomToken.sol" | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.9; | ||
import "@lukso/lsp-smart-contracts/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol"; | ||
import "@lukso/lsp-smart-contracts/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol"; | ||
contract CustomToken is LSP7Mintable, LSP7Burnable { | ||
// parameters for LSP7Mintable constructor are: | ||
// token name, | ||
// token symbol, | ||
// token owner, | ||
// boolean isNonDivisible | ||
// for more informations, check https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-7-DigitalAsset.md | ||
constructor() LSP7Mintable("My Custom Token", "MCT", msg.sender, false) { | ||
mint(msg.sender, 20000 * 10**decimals(), true, '0x' ); | ||
} | ||
} | ||
``` | ||
|
||
### 🍭 Bonus: create a MockContract to generate the UniversalProfile type | ||
|
||
In order to deploy this Custom LSP7 contract, we will interact with a UniversalProfile. We can enhance the developer experience by generating the types for a `UniversalProfile` contract. | ||
To do that, you can create a `MockContract.sol` file in the `contracts/` file with the following content: | ||
|
||
```solidity title="contracts/MyCustomToken.sol" | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.9; | ||
import {UniversalProfile} from '@lukso/lsp-smart-contracts/contracts/UniversalProfile.sol'; | ||
``` | ||
|
||
We are now ready to build our contracts using the command: | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
## Deploy our LSP7 Token contract on LUKSO Testnet | ||
|
||
We are now ready to deploy our contract on the [**LUKSO Testnet network**](../networks/testnet/parameters.md)! | ||
|
||
In order to deploy the contract, we will have to update the `hardhat.config.ts` and create a deploy script. Let's go! | ||
|
||
|
@@ -42,7 +149,7 @@ We will create a script to deploy the smart contract to the LUKSO Testnet networ | |
|
||
#### Deploy using a Universal Profile (Recommended) | ||
|
||
In this chapter, we are going to deploy our contract using our Universal Profile. First thing is to [Install the UP browser extension](../../guides/browser-extension/install-browser-extension.md). Once installed, we will retrieve the information we need: | ||
In this chapter, we are going to deploy our contract using our Universal Profile. First thing is to [Install the UP browser extension](../guides/browser-extension/install-browser-extension.md). Once installed, we will retrieve the information we need: | ||
|
||
- Click on the extension | ||
- Click on the cogwheel ⚙️ at the top right corner, then select "reveal private keys" | ||
|
@@ -52,7 +159,7 @@ In this chapter, we are going to deploy our contract using our Universal Profile | |
|
||
:::note | ||
|
||
The `privateKey` coming from your UP extension is the private key of the EOA that controls your UP (more information about controllers can be found in the [Key Manager](../../standards/universal-profile/lsp6-key-manager.md) page). You can find the associated address in the extension if you click on the controller tab > UP Extension. This address will need to be funded using the [Testnet Faucet](https://faucet.testnet.lukso.network/). | ||
The `privateKey` coming from your UP extension is the private key of the EOA that controls your UP (more information about controllers can be found in the [Key Manager](../standards/universal-profile/lsp6-key-manager.md) page). You can find the associated address in the extension if you click on the controller tab > UP Extension. This address will need to be funded using the [Testnet Faucet](https://faucet.testnet.lukso.network/). | ||
|
||
::: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
--- | ||
title: Interfaces IDs | ||
sidebar_position: 2 | ||
--- | ||
|
||
import InterfaceIdsTable from "./\_interface_ids_table.mdx"; | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters