In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 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 realize the DApp of Ethernet Square Intelligent contract". 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!
Sort out the architectural relationships:
The communication between web3.js and Ethernet Square is realized through rpc.
Ethernet Fong node originally provides rpc access method, but because the address of Ethernet Fong node is uncertain and DApp needs to access wallet, it is not realistic to use web3.js to directly access the rpc service of Ethernet Fong node.
Ganache-cli simulates a test node in Ethernet Square and provides external rpc access (which is often referred to as http://localhost:7545 or http://localhost:8545 in the example). At the same time, M Ethernet Square accounts are built in for testing.
MetaMask is an ethernet wallet plug-in, which also provides access to web3. And you can specify what the following etheric Fong node is through this plug-in. Because MetaMask is a wallet plug-in, it solves the payment problem in DApp. So today's DApp depends on it.
There is an ethernet tutorial, which is studied online. You can take a look. If you do it on your own machine, the basic process of developing DApp is the same as follows:
1. Install NodeJS
2. Install truffle: a development framework for developing DApp
Nmp install-g truffle
3. Install Ganache (originally using testrpc): simulate the operation of Ethernet Square in memory and provide rpc services to the outside.
Npm install-g ganache-cli
4. Run ganache-cli
Ganache-cli
5. Generate a DApp project
Mkdir project1truffle init
If you want to use an example in truffle, you can use the
Truffle unbox pet-shop
"pet-shop" is the name of the example
6. Write a smart contract
You can refer to various articles on how to write smart contracts in solidity, which will not be repeated here.
Put the Project1.sol file of the written intelligent contract into the contracts directory
7. Compile and deploy smart contracts
Create the file 2_deploy_contracts.js under the migrations directory:
Var Project1 = artifacts.require ("Project1"); module.exports = function (deployer) {deployer.deploy (Project1);}
Then execute:
Truffle compiletruffle migrate
If there is no problem with your smart contract, your ethernet square smart contract should have been deployed to the ganache you are testing.
The problem that may be encountered here is: in the default project generated by truffle, the address and port of the ganache used in the test will be set to http://localhost:7545, but in fact, the service port after ganache-cli is http://localhost:8545, which needs to be modified in truffle.js:
Module.exports = {/ / See / / for more about customizing your Truffle promotional networks: {development: {host: "127.0.0.1", port: 7545, / / change to 8545network_id: "*" / / Match any network id}
8. Write the front-end js code to interact with Etay Square
The following secondary js libraries are usually required:
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.