Skip to content

Commit 512995e

Browse files
migrate truffle to hardhat (#1390)
* migrate truffle to hardhat Signed-off-by: Joshua Fernandes <[email protected]> * Minor edits. Signed-off-by: bgravenorst <[email protected]> * adding warning to smart-contracts page Signed-off-by: Joshua Fernandes <[email protected]> * Minor edits. Signed-off-by: bgravenorst <[email protected]> * Fix admonition. Signed-off-by: bgravenorst <[email protected]> --------- Signed-off-by: Joshua Fernandes <[email protected]> Signed-off-by: bgravenorst <[email protected]> Co-authored-by: bgravenorst <[email protected]>
1 parent 2654332 commit 512995e

File tree

7 files changed

+209
-217
lines changed

7 files changed

+209
-217
lines changed

docs/private-networks/how-to/configure/free-gas.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ When gas is free, limiting block and contract sizes is less important. In free g
3434

3535
### 1. Set the block size
3636

37-
If you want to remove gas from consideration and don't mind blocks potentially taking longer to create, in the genesis file set the block size limit (measured in gas) to the maximum accepted by Truffle (`0x1fffffffffffff`). In the genesis file, specify `gasLimit` following the `config` key.
37+
If you want to remove gas from consideration and don't mind blocks potentially taking longer to create, in the genesis file set the block size limit (measured in gas) to the maximum accepted by Hardhat (`0x1fffffffffffff`). In the genesis file, specify `gasLimit` following the `config` key.
3838

3939
```json
4040
{
@@ -107,21 +107,21 @@ If your network is configured to use the `londonBlock` or a later hard fork, the
107107
}
108108
```
109109

110-
## Configure free gas in Truffle
110+
## Configure free gas in Hardhat
111111

112-
If using Truffle to develop on your free gas network, you also need to configure free gas in Truffle.
112+
If using Hardhat to develop on your free gas network, you also need to configure free gas in Hardhat.
113113

114-
Like setting block and contract size limits to their maximum values for Besu, set the transaction gas limit in Truffle to the maximum possible.
114+
Like setting block and contract size limits to their maximum values for Besu, set the transaction gas limit in Hardhat to the maximum possible.
115115

116116
:::info
117117

118-
Besu does not support private key management. To use Besu with Truffle, you must configure a [Truffle wallet](../../../public-networks/how-to/develop/truffle.md).
118+
Besu does not support private key management. To use Besu with Hardhat, you must configure a [Hardhat wallet](../../../public-networks/how-to/develop/hardhat.md).
119119

120120
:::
121121

122-
### Update `truffle-config.js`
122+
### Update `hardhat.config.js`
123123

124-
Update the `truffle-config.js` file:
124+
Update the `hardhat.config.js` file:
125125

126126
1. Set the gas price to zero.
127127

docs/private-networks/how-to/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The following features are shared with [public networks](../../public-networks/i
3030
- [Manage JVM memory](../../public-networks/how-to/configure-jvm/manage-memory.md)
3131
- [Use Java Flight Recorder](../../public-networks/how-to/configure-jvm/java-flight-recorder.md)
3232
- Develop dapps:
33-
- [Use Truffle](../../public-networks/how-to/develop/truffle.md)
33+
- [Use Hardhat](../../public-networks/how-to/develop/hardhat.md)
3434
- [Use client libraries](../../public-networks/how-to/develop/client-libraries.md)
3535
- Troubleshoot:
3636
- [Use EVM tool](../../public-networks/how-to/troubleshoot/evm-tool.md)

docs/private-networks/tutorials/permissioning/onchain.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ The following steps describe bootstrapping a permissioned network using a Hyperl
1212

1313
This tutorial configures permissioning on a [IBFT 2.0 proof of authority (PoA)] network.
1414

15+
:::caution Please use this as reference material only!
16+
17+
The [permissioning-contract-repo](https://github.com/ConsenSys/permissioning-smart-contracts) has been archived and is intended as reference material only.
18+
Please update all dependencies in there before proceeding.
19+
20+
In addition, we also recommend using [Hardhat](https://hardhat.org/hardhat-runner/docs/guides/deploying) instead of [Truffle](https://trufflesuite.com/),
21+
as the development environment. Please refer to the [Quorum Dev Quickstart](../../tutorials/quickstart.md) for an example.
22+
23+
:::
24+
1525
## Prerequisites
1626

1727
- [Node.js](https://nodejs.org/en/) v10.16.0 or later

docs/private-networks/tutorials/permissioning/upgrade-contracts.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ tags:
1010

1111
The following tutorial describes the steps to upgrade the onchain permissioning contracts to the latest version.
1212

13+
:::caution Please use this as reference material only!
14+
15+
The [permissioning-contract-repo](https://github.com/ConsenSys/permissioning-smart-contracts) has been archived and is intended as reference material only.
16+
Please update all dependencies in there before proceeding.
17+
18+
In addition we also recommend using [Hardhat](https://hardhat.org/hardhat-runner/docs/guides/deploying) instead of [Truffle](https://trufflesuite.com/),
19+
as the development environment. Please refer to the [Quorum Dev Quickstart](../../tutorials/quickstart.md) for an example.
20+
21+
:::
22+
1323
## Prerequisites
1424

1525
<!-- vale off -->
@@ -19,8 +29,10 @@ The following tutorial describes the steps to upgrade the onchain permissioning
1929
- [Yarn](https://yarnpkg.com/en/) v1.15 or later
2030
- Browser with [MetaMask installed](https://metamask.io/).
2131

32+
2233
## Steps
2334

35+
2436
### 1. Get the latest contracts and install dependencies
2537

2638
:::note

docs/private-networks/tutorials/quickstart.md

Lines changed: 105 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Postman from '../../global/postman.md';
1414

1515
The Quorum Developer Quickstart uses the Hyperledger Besu Docker image to run a private [IBFT 2.0](../how-to/configure/consensus/ibft.md) network of Besu nodes managed by Docker Compose.
1616

17-
:::danger
17+
:::caution
1818

1919
This tutorial runs a private network suitable for education or demonstration purposes and is not intended for running production networks.
2020

@@ -30,7 +30,7 @@ This tutorial runs a private network suitable for education or demonstration pur
3030
- Docker desktop configured to use the WSL2-based engine
3131
- [Docker and Docker Compose](https://docs.docker.com/compose/install/)
3232
- [Node.js](https://nodejs.org/en/download/) version 12 or higher
33-
- [Truffle](https://www.trufflesuite.com/truffle)
33+
- [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#overview)
3434
- [cURL command line](https://curl.haxx.se/download.html)
3535
- [MetaMask](https://metamask.io/)
3636

@@ -286,138 +286,100 @@ Besu doesn't incorporate [account management](../../public-networks/how-to/send-
286286

287287
## Smart contract and dapp usage
288288

289-
You can use a demo dapp called Pet Shop, provided by [Truffle](https://www.trufflesuite.com/tutorial).
289+
You can use a demo dapp called QuorumToken which uses an ERC20 token that is deployed to the network.
290290

291-
The dapp runs a local website using Docker, and uses smart contracts deployed on the network.
291+
We'll use [Hardhat](https://www.npmjs.com/package/hardhat), [Ethers](https://www.npmjs.com/package/ethers) and [MetaMask](https://metamask.io/) to interact with the network, which involves the following steps:
292292

293-
The directory created by `quorum-dev-quickstart` includes a `dapps` directory with a `pet-shop` subdirectory, which contains the source code for the dapp, including the smart contracts, website, and configurations to run this tutorial.
293+
1. Deploy the contract and **save the contract's address**.
294+
1. Start the dapp, and read and transact with the deployed token.
294295

295-
With the blockchain running and MetaMask connected to `Localhost 8545` via the browser, run the following command to start the Pet Shop dapp:
296+
The `dapps/quorumToken` directory is this structured in this manner (only relevant paths shown):
296297

297298
```bash
298-
cd dapps/pet-shop
299-
./run_dapp.sh
299+
quorumToken
300+
├── hardhat.config.ts // hardhat network config
301+
├── contracts // the QuorumToken.sol
302+
├── scripts // handy scripts eg: to deploy to a chain
303+
├── test // contract tests
304+
└── frontend // dapp done in next.js
305+
├── public
306+
├── src
307+
├── styles
308+
├── tsconfig.json
300309
```
301310

302-
The script:
303-
304-
1. Installs the dapp Node dependencies (you may see some warnings here, but it will not prevent the dapp from running).
305-
1. Compiles the contracts.
306-
1. Deploys the contracts to the blockchain.
307-
1. Runs tests.
308-
1. Builds and runs a Docker image to serve the dapp website.
309-
310-
```text './run_dapp.sh' example output
311-
Compiling your contracts...
312-
===========================
313-
> Compiling ./contracts/Adoption.sol
314-
> Compiling ./contracts/Migrations.sol
315-
> Artifacts written to /Users/demo/quorum-test-network/dapps/pet-shop/pet-shop-box/build/contracts
316-
> Compiled successfully using:
317-
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
318-
319-
Starting migrations...
320-
======================
321-
> Network name: 'quickstartWallet'
322-
> Network id: 1337
323-
> Block gas limit: 16234336 (0xf7b760)
324-
325-
1_initial_migration.js
326-
======================
327-
328-
Deploying 'Migrations'
329-
----------------------
330-
> transaction hash: 0xdd27f5bc5b0c4a42bb4f4d9ba00b4d33742de10ba8f03484cbf095ee824ba11a
331-
> Blocks: 0 Seconds: 0
332-
> contract address: 0xFB88dE099e13c3ED21F80a7a1E49f8CAEcF10df6
333-
> block number: 2747
334-
> block timestamp: 1618000437
335-
> account: 0x627306090abaB3A6e1400e9345bC60c78a8BEf57
336-
> balance: 89999.97435026
337-
> gas used: 221555 (0x36173)
338-
> gas price: 20 gwei
339-
> value sent: 0 ETH
340-
> total cost: 0.0044311 ETH
341-
342-
343-
> Saving migration to chain.
344-
> Saving artifacts
345-
-------------------------------------
346-
> Total cost: 0.0044311 ETH
347-
348-
2_deploy_contracts.js
349-
=====================
350-
351-
Deploying 'Adoption'
352-
--------------------
353-
> transaction hash: 0xd6f5b11807a0727a92b6063c95b9101769d310592b0d3cf35d6df233d05d50e6
354-
> Blocks: 0 Seconds: 0
355-
> contract address: 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a
356-
> block number: 2749
357-
> block timestamp: 1618000441
358-
> account: 0x627306090abaB3A6e1400e9345bC60c78a8BEf57
359-
> balance: 89999.968712
360-
> gas used: 239915 (0x3a92b)
361-
> gas price: 20 gwei
362-
> value sent: 0 ETH
363-
> total cost: 0.0047983 ETH
364-
365-
366-
> Saving migration to chain.
367-
> Saving artifacts
368-
-------------------------------------
369-
> Total cost: 0.0047983 ETH
370-
371-
Summary
372-
=======
373-
> Total deployments: 2
374-
> Final cost: 0.0092294 ETH
375-
376-
377-
Using network 'quickstartWallet'.
378-
379-
Compiling your contracts...
380-
===========================
381-
> Compiling ./test/TestAdoption.sol
382-
383-
TestAdoption
384-
✓ testUserCanAdoptPet (2071ms)
385-
✓ testGetAdopterAddressByPetId (6070ms)
386-
✓ testGetAdopterAddressByPetIdInArray (6077ms)
387-
388-
3 passing (37s)
311+
### Deploy the contract
312+
313+
Once the network is up and running, enter the `quorumToken` directory and run the following:
314+
315+
```bash
316+
# install dependencies
317+
npm i
318+
# compile the contract
319+
npm run compile
320+
npm run test
321+
# deploy the contract to the quickstart network
322+
npm run deploy-quorumtoken
389323
```
324+
The output is similar to the following:
390325

391-
After these tests are successful, the script builds a container for the Pet Shop dapp and deploys it, binding it to port 3001 on your system.
326+
```bash
392327

393-
```text
394-
Sending build context to Docker daemon 489.4MB
395-
Step 1/5 : FROM node:12.14.1-stretch-slim
396-
---> 2f7e25ad14ea
397-
Step 2/5 : EXPOSE 3001
398-
---> Using cache
399-
---> 2ef0665a040a
400-
Step 3/5 : WORKDIR /app
401-
---> Using cache
402-
---> e8e97cedb575
403-
Step 4/5 : COPY . /app
404-
---> f70e4265e598
405-
Step 5/5 : CMD npm run dev
406-
---> Running in 3c6e8bdb3f3b
407-
Removing intermediate container 3c6e8bdb3f3b
408-
---> ce2588e47ab0
409-
Successfully built ce2588e47ab0
410-
Successfully tagged quorum-dev-quickstart_pet_shop:latest
411-
b1615ab765656bc027f63fc60019dba1ca572305766c820f41eaf113b7e14cf8
328+
# compile
329+
330+
> npx hardhat compile
331+
332+
Generating typings for: 5 artifacts in dir: typechain-types for target: ethers-v6
333+
Successfully generated 24 typings!
334+
Compiled 5 Solidity files successfully
335+
336+
# test
337+
338+
> npx hardhat test
339+
340+
QuorumToken
341+
Deployment
342+
✔ Should have the correct initial supply (1075ms)
343+
✔ Should token transfer with correct balance (78ms)
344+
345+
346+
2 passing (1s)
347+
348+
# deploy
349+
Contract deploy at: 0x5FbDB2315678afecb367f032d93F642f64180aa3
350+
```
351+
This will deploy the contract to the network and return the address. **Please save this address for the next step**.
352+
353+
### Run the dapp
354+
355+
The dapp runs a local website using Next.js, and uses the contract in the previous step deployed on the network.
356+
357+
With the blockchain running, and MetaMask connected to `localhost` on port `8545`, import one of [our test accounts via private key](../reference/accounts-for-testing.md), and run the following command:
358+
359+
```bash
360+
cd frontend
361+
npm i
362+
npm run dev
412363
```
364+
This starts the dapp, binding it to port `3001` on your machine.
365+
366+
```text
413367
414-
In the browser where you have MetaMask enabled and one of the test accounts loaded, open a new tab and navigate to [the Pet Shop dapp](http://localhost:3001) where you can adopt lovely pets (sorry, not for real, it's a demo).
368+
369+
> next dev -p 3001
415370
416-
When you select **Adopt**, a MetaMask window pops up and requests your permission to continue with the transaction.
371+
- ready started server on [::]:3001, url: http://localhost:3001
372+
- event compiled client and server successfully in 270 ms (18 modules)
373+
- wait compiling...
374+
- event compiled client and server successfully in 173 ms (18 modules)
375+
```
417376

418-
After the transaction is complete and successful, the status of the pet you adopted shows **Success**.
377+
In the browser where you have MetaMask enabled and one of the test accounts loaded, open a new tab and navigate to
378+
[the QuorumToken dapp](http://localhost:3001).
379+
Connect to MetaMask and input the address from the previous step. Fox example our contract above deployed to `0x5FbDB2315678afecb367f032d93F642f64180aa3`.
419380

420-
![Dapp UI](../../assets/images/dapp-ui.png)
381+
The dapp will then read the balance of the account from MetaMask and get details of the contract. You can then send funds
382+
to another address (any of the other test accounts) on the network, and MetaMask will sign and send the transaction.
421383

422384
You can also search for the transaction and view its details in the [Block Explorer](http://localhost:25000/).
423385

@@ -429,42 +391,41 @@ The MetMask UI also keeps a record of the transaction.
429391

430392
### Deploy your own dapp
431393

432-
You can deploy your own dapp to the Quorum Developer Quickstart, by configuring your dapp to point to the Quickstart network.
394+
You can deploy your own dapp to the Quorum Developer Quickstart by configuring your dapp to point to the Quickstart network.
433395

434-
If you're using [Truffle](https://trufflesuite.com/truffle/), update the `networks` object in the [Truffle configuration file](https://trufflesuite.com/docs/truffle/reference/configuration#networks) to specify which networks to connect to for deployments and testing. The Quickstart RPC service endpoint is `http://localhost:8545`.
396+
We recommend using [Hardhat](https://hardhat.org/hardhat-runner/docs/guides/project-setup), and you can use the sample
397+
`hardhat.config.js` to configure the `networks` object in the [Hardhat configuration file](https://hardhat.org/hardhat-network/docs/reference#config)
398+
to specify which networks to connect to for deployments and testing. The Quickstart's RPC service endpoint is `http://localhost:8545`.
435399

436-
For example, the following is the Truffle configuration file for the Pet Shop dapp used in the Quickstart Besu network:
400+
For example, the following is the Hardhat configuration file for the QuorumToken dapp used in the Quickstart GoQuorum network:
437401

438402
```js
439-
const PrivateKeyProvider = require("@truffle/hdwallet-provider");
440-
441-
// insert the private key of the account used in MetaMask, e.g. Account 1 (Miner Coinbase Account)
442-
const privateKey =
443-
"c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3";
444-
445403
module.exports = {
446404
networks: {
447-
development: {
448-
host: "127.0.0.1",
449-
port: 7545,
450-
network_id: "*", // Match any network id
451-
},
452-
develop: {
453-
port: 8545,
454-
},
455-
quickstartWallet: {
456-
provider: () =>
457-
new PrivateKeyProvider(privateKey, "http://localhost:8545"),
458-
network_id: "*",
405+
// in built test network to use when developing contracts
406+
hardhat: {
407+
chainId: 1337
459408
},
460-
},
461-
};
409+
quickstart: {
410+
url: "http://127.0.0.1:8545",
411+
chainId: 1337,
412+
// test accounts only, all good ;)
413+
accounts: [
414+
"0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
415+
"0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
416+
"0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f"
417+
]
418+
}
419+
},
420+
defaultNetwork: "hardhat",
421+
...
422+
...
462423
```
463424
464-
Deploy the dapp using:
425+
Deploy the contract using:
465426
466427
```bash
467-
truffle migrate --network quickstartWallet
428+
npx hardhat run ./scripts/deploy_quorumtoken.ts --network quickstart
468429
```
469430
470431
## Stop and restart the private network without removing containers

0 commit comments

Comments
 (0)