From 26543323c128ca2ec5a3ba199b9eed78bfee65d5 Mon Sep 17 00:00:00 2001 From: Veervikram Singh <71558977+Vikramop@users.noreply.github.com> Date: Sat, 26 Aug 2023 00:08:10 +0530 Subject: [PATCH 1/2] removed null from engine_exchangeTransitionConfigurationV11 (#1389) * Doc new debug methods (#1379) * doc new debug methods Signed-off-by: Alexandra Tran * Apply suggestions from code review Co-authored-by: Sally MacFarlane Co-authored-by: Gabriel Fukushima Signed-off-by: Alexandra Tran Carrillo <12214231+alexandratran@users.noreply.github.com> * add array Signed-off-by: Alexandra Tran --------- Signed-off-by: Alexandra Tran Signed-off-by: Alexandra Tran Carrillo <12214231+alexandratran@users.noreply.github.com> Co-authored-by: Sally MacFarlane Co-authored-by: Gabriel Fukushima Signed-off-by: Veervikram singh * removed null from engine_exchangeTransitionConfigurationV11 Signed-off-by: Veervikram singh * removed null from engine_exchangeTransitionConfigurationV11 Signed-off-by: Veervikram singh --------- Signed-off-by: Alexandra Tran Signed-off-by: Alexandra Tran Carrillo <12214231+alexandratran@users.noreply.github.com> Signed-off-by: Veervikram singh Co-authored-by: Alexandra Tran Carrillo <12214231+alexandratran@users.noreply.github.com> Co-authored-by: Sally MacFarlane Co-authored-by: Gabriel Fukushima --- docs/public-networks/reference/engine-api/index.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/public-networks/reference/engine-api/index.md b/docs/public-networks/reference/engine-api/index.md index 0d44ea08603..ebb85e4a430 100644 --- a/docs/public-networks/reference/engine-api/index.md +++ b/docs/public-networks/reference/engine-api/index.md @@ -135,8 +135,7 @@ curl -X POST --data '{"jsonrpc":"2.0","method":"engine_exchangeTransitionConfigu "terminalTotalDifficulty": 0, "terminalBlockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "terminalBlockNumber": "0x1" - }, - "payloadId": null + } } ``` From 512995e5588c8e8e56dccccb3d748c51c7ba481e Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Tue, 29 Aug 2023 07:02:55 +1000 Subject: [PATCH 2/2] migrate truffle to hardhat (#1390) * migrate truffle to hardhat Signed-off-by: Joshua Fernandes * Minor edits. Signed-off-by: bgravenorst * adding warning to smart-contracts page Signed-off-by: Joshua Fernandes * Minor edits. Signed-off-by: bgravenorst * Fix admonition. Signed-off-by: bgravenorst --------- Signed-off-by: Joshua Fernandes Signed-off-by: bgravenorst Co-authored-by: bgravenorst --- .../how-to/configure/free-gas.md | 14 +- docs/private-networks/how-to/index.md | 2 +- .../tutorials/permissioning/onchain.md | 10 + .../permissioning/upgrade-contracts.md | 12 + docs/private-networks/tutorials/quickstart.md | 249 ++++++++---------- .../public-networks/how-to/develop/hardhat.md | 74 ++++++ .../public-networks/how-to/develop/truffle.md | 65 ----- 7 files changed, 209 insertions(+), 217 deletions(-) create mode 100644 docs/public-networks/how-to/develop/hardhat.md delete mode 100644 docs/public-networks/how-to/develop/truffle.md diff --git a/docs/private-networks/how-to/configure/free-gas.md b/docs/private-networks/how-to/configure/free-gas.md index 950ab0f1db6..9eccfd2666d 100644 --- a/docs/private-networks/how-to/configure/free-gas.md +++ b/docs/private-networks/how-to/configure/free-gas.md @@ -34,7 +34,7 @@ When gas is free, limiting block and contract sizes is less important. In free g ### 1. Set the block size -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. +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. ```json { @@ -107,21 +107,21 @@ If your network is configured to use the `londonBlock` or a later hard fork, the } ``` -## Configure free gas in Truffle +## Configure free gas in Hardhat -If using Truffle to develop on your free gas network, you also need to configure free gas in Truffle. +If using Hardhat to develop on your free gas network, you also need to configure free gas in Hardhat. -Like setting block and contract size limits to their maximum values for Besu, set the transaction gas limit in Truffle to the maximum possible. +Like setting block and contract size limits to their maximum values for Besu, set the transaction gas limit in Hardhat to the maximum possible. :::info -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). +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). ::: -### Update `truffle-config.js` +### Update `hardhat.config.js` -Update the `truffle-config.js` file: +Update the `hardhat.config.js` file: 1. Set the gas price to zero. diff --git a/docs/private-networks/how-to/index.md b/docs/private-networks/how-to/index.md index ae5ae0ada06..9884ebccd56 100644 --- a/docs/private-networks/how-to/index.md +++ b/docs/private-networks/how-to/index.md @@ -30,7 +30,7 @@ The following features are shared with [public networks](../../public-networks/i - [Manage JVM memory](../../public-networks/how-to/configure-jvm/manage-memory.md) - [Use Java Flight Recorder](../../public-networks/how-to/configure-jvm/java-flight-recorder.md) - Develop dapps: - - [Use Truffle](../../public-networks/how-to/develop/truffle.md) + - [Use Hardhat](../../public-networks/how-to/develop/hardhat.md) - [Use client libraries](../../public-networks/how-to/develop/client-libraries.md) - Troubleshoot: - [Use EVM tool](../../public-networks/how-to/troubleshoot/evm-tool.md) diff --git a/docs/private-networks/tutorials/permissioning/onchain.md b/docs/private-networks/tutorials/permissioning/onchain.md index e9d2353a0cd..2d2655b0b3c 100644 --- a/docs/private-networks/tutorials/permissioning/onchain.md +++ b/docs/private-networks/tutorials/permissioning/onchain.md @@ -12,6 +12,16 @@ The following steps describe bootstrapping a permissioned network using a Hyperl This tutorial configures permissioning on a [IBFT 2.0 proof of authority (PoA)] network. +:::caution Please use this as reference material only! + +The [permissioning-contract-repo](https://github.com/ConsenSys/permissioning-smart-contracts) has been archived and is intended as reference material only. +Please update all dependencies in there before proceeding. + +In addition, we also recommend using [Hardhat](https://hardhat.org/hardhat-runner/docs/guides/deploying) instead of [Truffle](https://trufflesuite.com/), +as the development environment. Please refer to the [Quorum Dev Quickstart](../../tutorials/quickstart.md) for an example. + +::: + ## Prerequisites - [Node.js](https://nodejs.org/en/) v10.16.0 or later diff --git a/docs/private-networks/tutorials/permissioning/upgrade-contracts.md b/docs/private-networks/tutorials/permissioning/upgrade-contracts.md index 00078d551b2..7d44a43b56a 100644 --- a/docs/private-networks/tutorials/permissioning/upgrade-contracts.md +++ b/docs/private-networks/tutorials/permissioning/upgrade-contracts.md @@ -10,6 +10,16 @@ tags: The following tutorial describes the steps to upgrade the onchain permissioning contracts to the latest version. +:::caution Please use this as reference material only! + +The [permissioning-contract-repo](https://github.com/ConsenSys/permissioning-smart-contracts) has been archived and is intended as reference material only. +Please update all dependencies in there before proceeding. + +In addition we also recommend using [Hardhat](https://hardhat.org/hardhat-runner/docs/guides/deploying) instead of [Truffle](https://trufflesuite.com/), +as the development environment. Please refer to the [Quorum Dev Quickstart](../../tutorials/quickstart.md) for an example. + +::: + ## Prerequisites @@ -19,8 +29,10 @@ The following tutorial describes the steps to upgrade the onchain permissioning - [Yarn](https://yarnpkg.com/en/) v1.15 or later - Browser with [MetaMask installed](https://metamask.io/). + ## Steps + ### 1. Get the latest contracts and install dependencies :::note diff --git a/docs/private-networks/tutorials/quickstart.md b/docs/private-networks/tutorials/quickstart.md index d89b5d31a63..abff0a9ab90 100644 --- a/docs/private-networks/tutorials/quickstart.md +++ b/docs/private-networks/tutorials/quickstart.md @@ -14,7 +14,7 @@ import Postman from '../../global/postman.md'; 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. -:::danger +:::caution This tutorial runs a private network suitable for education or demonstration purposes and is not intended for running production networks. @@ -30,7 +30,7 @@ This tutorial runs a private network suitable for education or demonstration pur - Docker desktop configured to use the WSL2-based engine - [Docker and Docker Compose](https://docs.docker.com/compose/install/) - [Node.js](https://nodejs.org/en/download/) version 12 or higher -- [Truffle](https://www.trufflesuite.com/truffle) +- [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#overview) - [cURL command line](https://curl.haxx.se/download.html) - [MetaMask](https://metamask.io/) @@ -286,138 +286,100 @@ Besu doesn't incorporate [account management](../../public-networks/how-to/send- ## Smart contract and dapp usage -You can use a demo dapp called Pet Shop, provided by [Truffle](https://www.trufflesuite.com/tutorial). +You can use a demo dapp called QuorumToken which uses an ERC20 token that is deployed to the network. -The dapp runs a local website using Docker, and uses smart contracts deployed on the network. +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: -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. +1. Deploy the contract and **save the contract's address**. +1. Start the dapp, and read and transact with the deployed token. -With the blockchain running and MetaMask connected to `Localhost 8545` via the browser, run the following command to start the Pet Shop dapp: +The `dapps/quorumToken` directory is this structured in this manner (only relevant paths shown): ```bash -cd dapps/pet-shop -./run_dapp.sh +quorumToken +├── hardhat.config.ts // hardhat network config +├── contracts // the QuorumToken.sol +├── scripts // handy scripts eg: to deploy to a chain +├── test // contract tests +└── frontend // dapp done in next.js + ├── public + ├── src + ├── styles + ├── tsconfig.json ``` -The script: - -1. Installs the dapp Node dependencies (you may see some warnings here, but it will not prevent the dapp from running). -1. Compiles the contracts. -1. Deploys the contracts to the blockchain. -1. Runs tests. -1. Builds and runs a Docker image to serve the dapp website. - -```text './run_dapp.sh' example output -Compiling your contracts... -=========================== -> Compiling ./contracts/Adoption.sol -> Compiling ./contracts/Migrations.sol -> Artifacts written to /Users/demo/quorum-test-network/dapps/pet-shop/pet-shop-box/build/contracts -> Compiled successfully using: - - solc: 0.5.16+commit.9c3226ce.Emscripten.clang - -Starting migrations... -====================== -> Network name: 'quickstartWallet' -> Network id: 1337 -> Block gas limit: 16234336 (0xf7b760) - -1_initial_migration.js -====================== - - Deploying 'Migrations' - ---------------------- - > transaction hash: 0xdd27f5bc5b0c4a42bb4f4d9ba00b4d33742de10ba8f03484cbf095ee824ba11a - > Blocks: 0 Seconds: 0 - > contract address: 0xFB88dE099e13c3ED21F80a7a1E49f8CAEcF10df6 - > block number: 2747 - > block timestamp: 1618000437 - > account: 0x627306090abaB3A6e1400e9345bC60c78a8BEf57 - > balance: 89999.97435026 - > gas used: 221555 (0x36173) - > gas price: 20 gwei - > value sent: 0 ETH - > total cost: 0.0044311 ETH - - - > Saving migration to chain. - > Saving artifacts - ------------------------------------- - > Total cost: 0.0044311 ETH - -2_deploy_contracts.js -===================== - - Deploying 'Adoption' - -------------------- - > transaction hash: 0xd6f5b11807a0727a92b6063c95b9101769d310592b0d3cf35d6df233d05d50e6 - > Blocks: 0 Seconds: 0 - > contract address: 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a - > block number: 2749 - > block timestamp: 1618000441 - > account: 0x627306090abaB3A6e1400e9345bC60c78a8BEf57 - > balance: 89999.968712 - > gas used: 239915 (0x3a92b) - > gas price: 20 gwei - > value sent: 0 ETH - > total cost: 0.0047983 ETH - - - > Saving migration to chain. - > Saving artifacts - ------------------------------------- - > Total cost: 0.0047983 ETH - -Summary -======= -> Total deployments: 2 -> Final cost: 0.0092294 ETH - - -Using network 'quickstartWallet'. - -Compiling your contracts... -=========================== -> Compiling ./test/TestAdoption.sol - -TestAdoption -✓ testUserCanAdoptPet (2071ms) -✓ testGetAdopterAddressByPetId (6070ms) -✓ testGetAdopterAddressByPetIdInArray (6077ms) - -3 passing (37s) +### Deploy the contract + +Once the network is up and running, enter the `quorumToken` directory and run the following: + +```bash +# install dependencies +npm i +# compile the contract +npm run compile +npm run test +# deploy the contract to the quickstart network +npm run deploy-quorumtoken ``` +The output is similar to the following: -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. +```bash -```text -Sending build context to Docker daemon 489.4MB -Step 1/5 : FROM node:12.14.1-stretch-slim ----> 2f7e25ad14ea -Step 2/5 : EXPOSE 3001 ----> Using cache ----> 2ef0665a040a -Step 3/5 : WORKDIR /app ----> Using cache ----> e8e97cedb575 -Step 4/5 : COPY . /app ----> f70e4265e598 -Step 5/5 : CMD npm run dev ----> Running in 3c6e8bdb3f3b -Removing intermediate container 3c6e8bdb3f3b ----> ce2588e47ab0 -Successfully built ce2588e47ab0 -Successfully tagged quorum-dev-quickstart_pet_shop:latest -b1615ab765656bc027f63fc60019dba1ca572305766c820f41eaf113b7e14cf8 +# compile +> quorumToken@1.0.0 compile +> npx hardhat compile + +Generating typings for: 5 artifacts in dir: typechain-types for target: ethers-v6 +Successfully generated 24 typings! +Compiled 5 Solidity files successfully + +# test +> quorumToken@1.0.0 test +> npx hardhat test + + QuorumToken + Deployment + ✔ Should have the correct initial supply (1075ms) + ✔ Should token transfer with correct balance (78ms) + + + 2 passing (1s) + +# deploy +Contract deploy at: 0x5FbDB2315678afecb367f032d93F642f64180aa3 +``` +This will deploy the contract to the network and return the address. **Please save this address for the next step**. + +### Run the dapp + +The dapp runs a local website using Next.js, and uses the contract in the previous step deployed on the network. + +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: + +```bash +cd frontend +npm i +npm run dev ``` +This starts the dapp, binding it to port `3001` on your machine. + +```text -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). +> webapp@0.1.0 dev +> next dev -p 3001 -When you select **Adopt**, a MetaMask window pops up and requests your permission to continue with the transaction. +- ready started server on [::]:3001, url: http://localhost:3001 +- event compiled client and server successfully in 270 ms (18 modules) +- wait compiling... +- event compiled client and server successfully in 173 ms (18 modules) +``` -After the transaction is complete and successful, the status of the pet you adopted shows **Success**. +In the browser where you have MetaMask enabled and one of the test accounts loaded, open a new tab and navigate to +[the QuorumToken dapp](http://localhost:3001). +Connect to MetaMask and input the address from the previous step. Fox example our contract above deployed to `0x5FbDB2315678afecb367f032d93F642f64180aa3`. -![Dapp UI](../../assets/images/dapp-ui.png) +The dapp will then read the balance of the account from MetaMask and get details of the contract. You can then send funds +to another address (any of the other test accounts) on the network, and MetaMask will sign and send the transaction. You can also search for the transaction and view its details in the [Block Explorer](http://localhost:25000/). @@ -429,42 +391,41 @@ The MetMask UI also keeps a record of the transaction. ### Deploy your own dapp -You can deploy your own dapp to the Quorum Developer Quickstart, by configuring your dapp to point to the Quickstart network. +You can deploy your own dapp to the Quorum Developer Quickstart by configuring your dapp to point to the Quickstart network. -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`. +We recommend using [Hardhat](https://hardhat.org/hardhat-runner/docs/guides/project-setup), and you can use the sample +`hardhat.config.js` to configure the `networks` object in the [Hardhat configuration file](https://hardhat.org/hardhat-network/docs/reference#config) +to specify which networks to connect to for deployments and testing. The Quickstart's RPC service endpoint is `http://localhost:8545`. -For example, the following is the Truffle configuration file for the Pet Shop dapp used in the Quickstart Besu network: +For example, the following is the Hardhat configuration file for the QuorumToken dapp used in the Quickstart GoQuorum network: ```js -const PrivateKeyProvider = require("@truffle/hdwallet-provider"); - -// insert the private key of the account used in MetaMask, e.g. Account 1 (Miner Coinbase Account) -const privateKey = - "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3"; - module.exports = { networks: { - development: { - host: "127.0.0.1", - port: 7545, - network_id: "*", // Match any network id - }, - develop: { - port: 8545, - }, - quickstartWallet: { - provider: () => - new PrivateKeyProvider(privateKey, "http://localhost:8545"), - network_id: "*", + // in built test network to use when developing contracts + hardhat: { + chainId: 1337 }, - }, -}; + quickstart: { + url: "http://127.0.0.1:8545", + chainId: 1337, + // test accounts only, all good ;) + accounts: [ + "0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63", + "0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3", + "0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f" + ] + } + }, + defaultNetwork: "hardhat", + ... + ... ``` -Deploy the dapp using: +Deploy the contract using: ```bash -truffle migrate --network quickstartWallet +npx hardhat run ./scripts/deploy_quorumtoken.ts --network quickstart ``` ## Stop and restart the private network without removing containers diff --git a/docs/public-networks/how-to/develop/hardhat.md b/docs/public-networks/how-to/develop/hardhat.md new file mode 100644 index 00000000000..06b4a800171 --- /dev/null +++ b/docs/public-networks/how-to/develop/hardhat.md @@ -0,0 +1,74 @@ +--- +title: Use Hardhat +sidebar_position: 1 +description: Using Hyperledger Besu with Hardhat +tags: + - public networks + - private networks +--- + +# Use Hardhat + +Developing for Hyperledger Besu using Hardhat is the same as developing for public Ethereum networks using Hardhat. Hardhat +supports Besu with the only difference being Besu does not support private key management. + +You can therefore use a wallet provider, or specify your private key in the code. + +## Private key management + +### Use an HD wallet + +To add the wallet provider, update the `hardhat.config.ts` file in the project directory. Replace: + +- `` with the JSON-RPC endpoint (IP address and port) of a Besu node. +- `` with the list of words that make up your account's mnemonic. +- ` your password if used +- `` your account's private key + +```js +module.exports = { + // See + // for more about customizing your Hardhat configuration! + networks: { + besuWallet: { + url: "", + accounts: { + mnemonic: "", + path: "m/44'/60'/0'/0", + initialIndex: 0, + count: 1, + passphrase: "", + }, + }, + }, +}; +``` + +### Specify your private key in code + +:::danger + +Ensure you do not commit private keys to source control like Github, always inject your keys at runtime as environment variables, or +use a vault or similar. + +::: + +```js +const provider = new ethers.JsonRpcApiProvider(); +const wallet = new ethers.Wallet(); +// connect the wallet to the provider +const signer = wallet.connect(provider); + +``` + +## Start a Besu node + +Start a Besu node with JSON-RPC enabled on the endpoint specified in the Hardhat configuration file. + +## Deploy a contract + +To deploy a contract onto the Besu network: + +```bash +npx hardhat scripts run ./scripts/deploy_my_contract.ts --network besuWallet +``` diff --git a/docs/public-networks/how-to/develop/truffle.md b/docs/public-networks/how-to/develop/truffle.md deleted file mode 100644 index a97d5d4620a..00000000000 --- a/docs/public-networks/how-to/develop/truffle.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: Use Truffle -sidebar_position: 1 -description: Using Hyperledger Besu with Truffle -tags: - - public networks - - private networks ---- - -# Use Truffle - -Developing for Hyperledger Besu using Truffle is the same as developing for public Ethereum networks using Truffle. Truffle supports Besu with the only difference being Besu does not support private key management. To use Besu with Truffle, you must configure a Truffle wallet. - -## Install a Truffle wallet - -To install a Truffle wallet: - -```bash -npm install --save @truffle/hdwallet-provider -``` - -:::note - -With Truffle 5, you must use a Web3 1.0 enabled wallet or the Truffle tasks hang. - -::: - -### Update the Truffle configuration file - -To add the wallet provider, update the `truffle-config.js` file in the project directory. Replace: - -- `` with the JSON-RPC endpoint (IP address and port) of a Besu node. -- `` with the private key of an Ethereum account containing Ether. - -```javascript -const PrivateKeyProvider = require("@truffle/hdwallet-provider"); -const privateKey = ""; -const privateKeyProvider = new PrivateKeyProvider( - privateKey, - "", -); - -module.exports = { - // See - // for more about customizing your Truffle configuration! - networks: { - besuWallet: { - provider: privateKeyProvider, - network_id: "*", - }, - }, -}; -``` - -### Start a Besu node - -Start a Besu node with JSON-RPC enabled on the endpoint specified in the Truffle configuration file. - -### Deploy a contract - -To deploy a contract onto the Besu network: - -```bash -truffle migrate --network besuWallet -```