Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Hardhat guide as Getting Started for Contracts #637

Merged
merged 4 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!

Expand Down Expand Up @@ -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"
Expand All @@ -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/).

:::

Expand Down
1 change: 0 additions & 1 deletion docs/contracts/interface-ids.md
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";
Expand Down
3 changes: 0 additions & 3 deletions docs/guides/hardhat-walkthrough/_category_.yml

This file was deleted.

48 changes: 0 additions & 48 deletions docs/guides/hardhat-walkthrough/create-custom-lsp7.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not forget redirects in the config so existing external links to this page don't get broken

This file was deleted.

71 changes: 0 additions & 71 deletions docs/guides/hardhat-walkthrough/hardhat-base-setup.md

This file was deleted.

12 changes: 12 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ module.exports = {
from: '/standards/standards-roadmap',
to: '/standards/introduction',
},
{
from: '/guides/hardhat-walkthrough/hardhat-base-setup',
to: '/contracts/getting-started',
},
{
from: '/guides/hardhat-walkthrough/create-custom-lsp7',
to: '/contracts/getting-started',
},
{
from: '/guides/hardhat-walkthrough/deploy-custom-lsp7',
to: '/contracts/getting-started',
},
],
},
],
Expand Down
15 changes: 8 additions & 7 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ module.exports = {
guidesSidebar: [{ type: 'autogenerated', dirName: 'guides' }],
contractsSidebar: [
'contracts/introduction',
'contracts/interface-ids',
'contracts/getting-started',
// divider for the main smart contracts
{ type: 'html', value: '<hr/>', defaultStyle: false },
{
type: 'category',
label: '📑 Smart Contracts',
label: 'Smart Contracts',
collapsible: true,
collapsed: false,
items: [
Expand All @@ -30,34 +30,35 @@ module.exports = {
},
],
},
// divider for the Contracts ABI Technical references
// divider for the Contracts ABI and Libraries Technical references
{ type: 'html', value: '<hr/>', defaultStyle: false },
{
type: 'category',
label: '📑 ABI Technical Reference',
collapsible: true,
collapsed: false,
collapsed: true,
items: [
{
type: 'autogenerated',
dirName: 'contracts/contracts',
},
],
},
// divider for the Libraries Technical references
{ type: 'html', value: '<hr/>', defaultStyle: false },
{
type: 'category',
label: '📒 Solidity Libraries',
collapsible: true,
collapsed: false,
collapsed: true,
items: [
{
type: 'autogenerated',
dirName: 'contracts/libraries',
},
],
},
// divider for the Libraries Technical references
{ type: 'html', value: '<hr/>', defaultStyle: false },
'contracts/interface-ids',
],
toolsSidebar: [
'tools/getting-started',
Expand Down