Skip to content

Commit

Permalink
remove getting started guide
Browse files Browse the repository at this point in the history
  • Loading branch information
fhildeb committed Feb 7, 2024
1 parent 7e57301 commit 58a397e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 141 deletions.
152 changes: 13 additions & 139 deletions smart-contracts-hardhat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ This project is used as a guide to show how to setup HardHat to work with the **

smart contracts on EVM based blockchains.

> Further information can be found on our [Hardhat Guide](https://docs.lukso.tech/learn/smart-contract-developers/getting-started).
## Guides

- [Getting started with HardHat on LUKSO](https://docs.lukso.tech/learn/smart-contract-developers/getting-started)
- [Create, deploy, and verify an LSP7 token](https://docs.lukso.tech/learn/smart-contract-developers/create-lsp7-token)

## Setup

Expand All @@ -26,35 +29,35 @@ Set the private environment variables
cp .env.example .env
```

> **INFO** Make sure to add the private key of an EOA for deployment. Optionally, you can provide a private key of a controller and a Universal Profile address to deploy via profile.
> **INFO** Make sure to add the private key of an EOA for deployment. Optionally, you can provide a private key of a controller and a Universal Profile address to deploy contracts using your smart contract account.
## Development

### Compile Contracts

Enforce compilation of contracts, and display the detailed stack traces for debugging.
Enforce the compilation of contracts and display the stack traces:

```bash
npm run build
```

Regular compilation of your smart contracts.
Regular compilation of your smart contracts:

```bash
npx hardhat compile
```

> **INFO** Add the `--verbose` and `--show-stack-traces` flags for further information
> **INFO** Add the `--verbose` and `--show-stack-traces` flags for further information.
### Deploy Scripts
### Deploy Contracts

Deploy a contract as an Externally Owned Account (EOA)
Deploy a sample LSP7 contract with an Externally Owned Account:

```bash
npx hardhat --network luksoTestnet run scripts/deployEOA.ts
```

Deploy a contract as a Universal Profile (UP)
Deploy a sample LSP7 contract with a Universal Profile:

```bash
npx hardhat --network luksoTestnet run scripts/deployUP.ts
Expand All @@ -64,141 +67,12 @@ npx hardhat --network luksoTestnet run scripts/deployUP.ts
### Verify Contracts

Verify your contracts with the blockscout API and their constructor parameters:

```bash
npx hardhat verify myTokenAddress --constructor-args ./verify/myTokenName.ts --network luksoTestnet
```

## Getting Started

The syntax of smart contracts works by **inheritance**, using underlying functionalities to smart contract objects. If you create a new smart contract using LSPs, you can `import` standardized and modular presets from the `@lukso/lsp-smart-contracts` developer library. Such presets can then be combined to create complex contract deployments like Universal Profiles and Digital Assets.

For example, you can import `LSP7Mintable` to create a LSP7 contract that enables the contract owner to mint these tokens like the following:

```js
// contracts/MyTokens/MyCustomToken.sol
import { LSP7Mintable } from "@lukso/lsp-smart-contracts/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol";
```

### Inherit LSP functionality

```js
// contracts/MyTokens/MyCustomToken.sol
...

contract MyToken is LSP7Mintable {
// custom smart contract logic ...
}
```

### Specify standardized parameters

After inheriting, the contract might expect mandatory parameters to fullfil the standardization. In case of `LSP7Mintable`, you must define a set of default parameters in the constructor of the smart contract, defined during the contracts deployment:

- its name
- its symbol
- the address that control the token
- the type of asset it is (Token, NFT or Collection)
- if the token can be divided in fractional units (LSP7 specific)

```js
// contracts/MyTokens/MyCustomToken.sol
...

contract MyToken is LSP7Mintable {
constructor(
string memory name,
string memory symbol,
address contractOwner,
uint256 lsp4TokenType,
bool isNonDivisible
) LSP7Mintable(
name,
symbol,
contractOwner,
lsp4TokenType,
isNonDivisible,
) {
}
// custom smart contract logic
}
```

### Add the deployment scripts

You can either write properties directly **into the Solditity contract** or **pass them from the deployment scripts**.

```js
// scripts/deployEOA.ts
import { ethers } from "hardhat";
import * as dotenv from "dotenv";

dotenv.config();

async function deployToken() {
const [deployer] = await ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);

const token = await ethers.deployContract("MyToken", [
"My Custom Token", // token name
"MCT", // token symbol
deployer.address, // contract owner
0, // token type = TOKEN
false, // isNonDivisible?
]);

console.log("Token address:", await token.getAddress());
}

deployToken()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
```

You can run the deployment script [as described above](#deploy-scripts).

### Interact with contract storage

After the token was deployed, you can access and edit the token's metadata on the storage:

```js
// scripts/deployEOA.ts
...

import { LSP4_TOKEN_TYPES, ERC725YDataKeys } from '@lukso/lsp-smart-contracts';

async function deployToken() {

...

// Read the token metadata
const metadata = await token.getData(ERC725YDataKeys.LSP4['LSP4Metadata']);
console.log('Token metadata:', metadata);

// Write token metadata (should be a VerifiableURI)
const tx = await token.setData(
ERC725YDataKeys.LSP4['LSP4Metadata'],
'0xcafecafe',
);

// Fetch the transaction receipt
const receipt = await tx.wait();
console.log('Token metadata updated:', receipt);
}

...
```

> **Info** You can only set one file as `VerifiableURI` for a token. This file will include all the data and media references. If you want to update individual properties, please get the latest contents of a contract's storage key, modify specific properties, and reupload the full file. This can then be used to edit the storage by calling the `setData()` function.
### Verify deployed contracts

To verify a deployed contract, you can use the blockscout API properties set up within the `hardhat.config.ts` of this repository. You then have to pass a file with all the constructor arguments that you've defined when deploying the smart contract. The parameters and compiled contract code are is then used to verify if it matches the payload of the deployed contract. You can find an example within [`/verify/myCustomToken.ts`](./verify/myCustomToken.ts)

You can run the verification script as [described above](#verify-contracts).

## Packages

- [`hardhat`](https://hardhat.org/docs): Smart contract development environment
Expand Down
4 changes: 2 additions & 2 deletions smart-contracts-hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ const config: HardhatUserConfig = {
network: 'luksoTestnet',
chainId: 4201,
urls: {
apiURL: 'https://api.explorer.execution.testnet.lukso.network/api',
apiURL: 'https://explorer.execution.testnet.lukso.network/api',
browserURL: 'https://explorer.execution.testnet.lukso.network/',
},
},
{
network: 'luksoMainnet',
chainId: 42,
urls: {
apiURL: 'https://api.explorer.execution.mainnet.lukso.network/api',
apiURL: 'https://explorer.execution.mainnet.lukso.network/api',
browserURL: 'https://explorer.execution.mainnet.lukso.network/',
},
},
Expand Down

0 comments on commit 58a397e

Please sign in to comment.