In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to use Truffle to develop Enterprise Ethernet Square DApp". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Besu is an enterprise ethernet product in Hyperledger, and its biggest advantage is that it is compatible with ethernet.
1. Start the enterprise ethernet network
Ethersquare tutorial recommendation: introduction to Dapp | E-commerce Dapp practice | Token practice | Php docking | Java docking | Python docking | C# docking | Dart docking
First, clone the source code of Besu's quickstart repository:
Git clone https://github.com/PegaSysEng/besu-quickstart.git
Then go to the besu-quickstart directory and execute the following command to build the docker image of besu:
. / run.sh
The above command builds a docker image and launches four containers to simulate an enterprise ethernet network with six besu nodes. When the script is finished, you can see the following output:
* * Besu Quickstart * * List endpoints and services-- Name Command State Ports- -besu-quickstart_bootnode_1 / opt/besu/bootnode_sta... Up 30303/tcp, 8545/tcp, 8546/tcpbesu-quickstart_explorer_1 nginx-g daemon off; Up 0.0.0.0 8546/tcpbesu-quickstart_explorer_1 nginx 32768-> 80/tcpbesu-quickstart_grafana_1 / run.sh Up 3000/tcpbesu-quickstart_minernode_1 / opt/besu/node_start.s. Up 30303/tcp, 8545/tcp, 8546/tcpbesu-quickstart_node_1 / opt/besu/node_start.s... Up 30303/tcp, 8545/tcp, 8546/tcpbesu-quickstart_node_2 / opt/besu/node_start.s... Up 30303/tcp, 8545/tcp, 8546/tcpbesu-quickstart_node_3 / opt/besu/node_start.s... Up 30303/tcp, 8545/tcp, 8546/tcpbesu-quickstart_node_4 / opt/besu/node_start.s... Up 30303/tcp, 8545/tcp, 8546/tcpbesu-quickstart_prometheus_1 / bin/prometheus-- config.f. Up 9090/tcpbesu-quickstart_rpcnode_1 / opt/besu/node_start.s... Up 30303/tcp, 8545/tcp, 8546/tcp
And the list of access nodes:
* JSON-RPC HTTP service endpoint: http://localhost:32768/jsonrpcJSON-RPC WebSocket service endpoint: ws://localhost:32768/jsonwsGraphQL HTTP service endpoint: http://localhost:32768/graphqlWeb block explorer address Http://localhost:32768Prometheus address: http://localhost:32768/prometheus/graphGrafana address: http://localhost:32768/grafana-dashboard * * * *
JSON-RPC HTTP service for access to DApp or Metamask wallets
JSON-RPC WebSocket service is used for DApp to access nodes through websocket
GraphQL HTTP service GraphQL service for access nodes of DApp or Metamask wallets
The Web block browsing service is used to browse blocks. Enter the address in your browser.
The Prometheus service is used to provide metric data for the Prometheus dashboard
The Grafana service is used to provide data for Grafana dashboards
To display the access node again, you can use the following command:
. / list.sh2, use the enterprise ethernet block browser
In this tutorial we use Alethio lightweight ethernet square browser, you can also use EthScan.
Open the address listed in the web block explorer endpoint mentioned above in your browser and you can view the block data in the enterprise ethernet network.
You can see six besu nodes in the block browser: four normal nodes, one outgoing block node, and one boot node.
Click the block number to the right of the Best Block to display the detailed data of the block:
Click the magnifying glass in the upper left corner to search for blocks, transaction hashes, or Ethernet Fong addresses:
3. Monitor the operation status of Besu nodes
Operation and maintenance monitoring tools such as Prometheus and Grafana can be used to visualize the health and operation of nodes. Referring to the access nodes given above, you can access these tools directly in your browser. For example, using Grafana:
4. Use JSON-RPC to access the Besu node
Besu supports the standard Ethernet Square JSON-RPC API interface. For example, use curl to call the web3_clientVersion command to view the version of the node:
Curl-X POST-- data'{"jsonrpc": "2.0", "method": "web3_clientVersion", "params": [], "id": 1}'
It indicates the address of the access node listed above, which you need to replace according to your actual situation, such as http://localhost:32768/jsonrpc. The return result of the above command is similar to the following:
{"jsonrpc": "2.0"," id ": 1," result ":" besu/ "}
Or use the net_peerCount command to check the number of Peer connected to the node:
Curl-X POST-- data'{"jsonrpc": "2.0", "method": "net_peerCount", "params": [], "id": 1}'
The results are as follows:
{"jsonrpc": "2.0"," id ": 1," result ":" 0x6 "}
Or use eth_blockNumber to view the latest block number:
Curl-X POST-- data'{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1}'
The results are as follows:
{"jsonrpc": "2.0"," id ": 1," result ":" 0x8b8 "} 5. Use MetaMask to create an enterprise ethernet transaction
Before sending an enterprise ethernet transaction, we need to create an account or use several accounts already declared in the creation configuration of this VPC:
Account number 1: it is also the currency base address
Address: 0xfe3b557e8fb62b89f4916b721be55ceb828dbd73Private key: 0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63Initial balance: 0xad78ebc5ac6200000 (2000000000000000000 in decimal)
Account number 2:
Address: 0x627306090abaB3A6e1400e9345bC60c78a8BEf57Private key: 0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3Initial balance: 0x90000000000000000000000 (2785365088392105618523029504 in decimal)
Account number 3:
Address: 0xf17f52151EbEF6C7334FAD080c5704D77216b732Private key: 0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162fInitial balance: 0x90000000000000000000000 (2785365088392105618523029504 in decimal
After logging in to MetaMask, link to a node of the Besu network we built, and then you can create a deal.
6. Demonstration of Truffle Pet Store based on Besu Network
To run Truffle's Pet Shop demo, we first need to install truffle and pet-shop templates, and then we need to make some simple adjustments to Besu's enterprise ethernet network.
Install truffle first:
Npm install-g truffle
Then create the pet-shop-tutorial directory and enter it:
Mkdir pet-shop-tutorialcd pet-shop-tutorial
Then extract the pet-shop box of Truffle:
Truffle unbox pet-shop
Install truffle-wallet:
Npm install-- save @ truffle/hdwallet-provider
Next, modify the truffle-config.js file in the pet-shop-tutorial directory to add our wallet provider. Please refer to the following for modification:
Const PrivateKeyProvider = require ("truffle-hdwallet-provider"); const privateKey = "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"; module.exports = {/ / See / / for more about customizing your Truffle configuration! Networks: {development: {host: "127.0.0.1", port: 7545, network_id: "*" / / Match any network id}, quickstartWallet: {provider: () = > new PrivateKeyProvider (privateKey, "), network_id:" * "},}
Will be replaced with your HTTP RPC access node, such as http://localhost:32770/jsonrpc.
Replace privateKey with the previous account 1, the base address, where there are etheric coins.
Because we use the enterprise ethernet network instead of the Ganache simulator, we need to specify the network when performing the contract deployment:
Truffle migrate-network quickstartWallet
The output is similar to the following:
Sing network 'quickstartWallet'.Running migration: 1_initial_migration.js Deploying Migrations... ... 0xfc1dbc1eaa14fa283c2c4415364579da0d195b3f2f2fefd7e0edb600a6235bdb Migrations: 0x9a3dbca554e9f6b9257aaa24010da8377c57c17eSaving successful migration to network... ... 0x77cc6e9966b886fb74268f118b3ff44cf973d32b616ed4f050b3eabf0a31a30eSaving artifacts...Running migration: 2_deploy_contracts.js Deploying Adoption... ... 0x5035fe3ea7dab1d81482acc1259450b8bf8fefecfbe1749212aca86dc765660a Adoption: 0x2e1f232a9439c3d459fceca0beef13acc8259dd8Saving successful migration to network... ... 0xa7b5a36e0ebc9c25445ce29ff1339a19082d0dda516e5b72c06ee6b99a901ec0Saving artifacts...
You can view the contract address in the above output in the block browser.
Similarly, specify the use of our corporate ethernet network when performing the test:
Truffle test-network quickstartWallet
The output is as follows:
Using network 'quickstartWallet'.Compiling. / contracts/Adoption.sol...Compiling. / test/TestAdoption.sol...Compiling truffle/Assert.sol...Compiling truffle/DeployedAddresses.sol... TestAdoption ✓ testUserCanAdoptPet (2071ms) ✓ testGetAdopterAddressByPetId (6070ms) ✓ testGetAdopterAddressByPetIdInArray (6077ms) 3 passing (37s) 7, stop / restart / clean up of the Enterprise Ethernet Fong network
Use the following script to stop the enterprise ethernet network made up of Besu without deleting the dockers container:
. / stop.sh
Restart the enterprise ethernet network using the following command:
. / resume.sh
If you want to stop the network and delete the corresponding docker container, use the following command:
. / remove.sh "how to use Truffle to develop Enterprise Ethernet Square DApp" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.