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

Migrate truffle to hardhat and new Dapp with ethers & hardhat #271

Merged
merged 3 commits into from
Aug 28, 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
10 changes: 0 additions & 10 deletions files/common/dapps/pet-shop/custom_config/Dockerfile

This file was deleted.

7 changes: 0 additions & 7 deletions files/common/dapps/pet-shop/custom_config/bs-config.json

This file was deleted.

19 changes: 0 additions & 19 deletions files/common/dapps/pet-shop/custom_config/contracts/Adoption.sol

This file was deleted.

This file was deleted.

121 changes: 0 additions & 121 deletions files/common/dapps/pet-shop/custom_config/src/js/app.js

This file was deleted.

25 changes: 0 additions & 25 deletions files/common/dapps/pet-shop/run_dapp.sh

This file was deleted.

11 changes: 11 additions & 0 deletions files/common/dapps/quorumToken/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts

74 changes: 74 additions & 0 deletions files/common/dapps/quorumToken/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Using a DApp to interact with the blockchain

This DApp, uses Hardhat and Ethers.js in combination with a self custodial (also called a user controlled) wallet i.e. Metamask to interact with the chain. As such this process esentially comprises two parts:

1. Deploy the contract to the chain
2. Use the DApp's interface to send and transact on the chain

The `dapps/quorumToken` folder is this structured in this manner (only relevant paths shown):

```
quorumToken
├── hardhat.config.ts // hardhat network config
├── contracts // sample contracts of which we use the QuorumToken.sol
├── scripts // handy scripts eg: to deploy to a chain
├── test // contract tests
└── frontend // DApp done in next.js
├── README.md
├── public
├── src
├── styles
├── tsconfig.json
```

# Contracts

Contracts are written in Solidity and we use the hardhat development environment for testing, deploying etc

The `hardhat.config.js` specifies the networks, accounts, solidity version etc

Install dependencies

```
npm i
```

Compile the contracts and run tests (optional):

```
npx run compile
# As you develop contracts you are using the inbuilt `hardhat` network
npx hardhat test
```

Deploy contracts with:

```
# we specify the network here so the DApp can use the contract, but you can use any network you wish to and remember to connect Metamask to the appropriate network for the DApp
npx hardhat run ./scripts/deploy_quorumtoken.ts --network quickstart
```

_Please remember to save the address returned from the deploy as you will need it for the following steps_

# DApp

We have a sample DApp created that uses Next.js, react and ethers to interact with the quickstart network

```
cd frontend
npm i
npm run dev
```

1. Open up a tab on port 3001 and connect to Metamask.
2. To interact with the DApp you will need to import the test accounts from `hardhat.config.ts`

For brevity they are the following:

```
0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63
0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3
0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f
```

3. When you connect to Metamask, you are presented with a field to input the address of the deployed contract from the previous step. The app will then fetch the contract data and you can then transfer eth to a new another account.
12 changes: 12 additions & 0 deletions files/common/dapps/quorumToken/contracts/QuorumToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract QuorumToken is ERC20 {
constructor(uint256 initialSupply)
ERC20("QuorumToken", "QT")
{
_mint(msg.sender, initialSupply);
}
}
3 changes: 3 additions & 0 deletions files/common/dapps/quorumToken/frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
35 changes: 35 additions & 0 deletions files/common/dapps/quorumToken/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
6 changes: 6 additions & 0 deletions files/common/dapps/quorumToken/frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
}

module.exports = nextConfig
Loading
Loading