First, use web3 to connect to the Ethereum network (test network, main network)
1. What is web3
- Web3.eth: Used to interact with the Ethereum blockchain and smart contracts. Web3.utils: Contains some helper methods.
- Web3.shh: P2P and broadcast for protocol communication.
- Web3.bzz: Bzz module for interacting with the group network.
- Github address: web3.js
- Web3.js development documentation::web3.js
2. Instantiate the web3 object
Web3 needs to interact with the node, you need to create a web3 object, let's see how to create it.
- How to choose cryptography technology? Final exploration of the security model of quantum computing communication
- Babbitt Column | Gu Yanxi: Against Dogmatism in Blockchain Applications
- How should the Blockchain Foundation and DAO be designed? Learn from Centennial Experience of the American Foundation
- Visiting Professor of National University of Singapore Bai Shihuan: All rights and real assets in the real world can be tokenized
- Research: Five major effects of central bank digital currency
- Industrial Cannabis + Blockchain: Seven Questions Tianyi Xinma
According to the API, we need to specify the node address, we will ws://some.local-or-remote.node:8546
The network of the connected Ethereum is determined by replacing the address of another node connected to the Ethereum network. So what is the address of the node connected to the Ethereum network? Here we need to use infura.
3. Get the node address connected to the Ethereum network
Infura provides the public Ethereum main network and test network nodes. After registering on the infura.io website, you can get the addresses of each network. Please follow the steps below to get the address.
The first step : open the infura website address: https://infura.io/dashboard, use the email to register and log in as follows:
Step 2 : Click on the “create new project” button labeled above to create a new project. Then pop up the following box, enter the project name in the input box, such as "MyEtherWallet", and then click the "create project" button to create.
Step 3 : Then the following interface will be displayed. Click the checkbox in the figure below to see the node addresses of the main network, Kovan test network, Ropsten test network, and Rinkeby test network.
Step 4 : Select Kovan to test the network, then copy the address and you will get an address like this:
Https://kovan.infura.io/v3/d93f…cd67, as follows.
4. Connect to the Ethereum Kovan Test Network
Now replace the copied address with the address of the instantiated web object, as follows
Connect to the Ethereum main network and the Kovan test network, just copy the address of the main network node to instantiate web3. Since the transaction on the main network requires cost, we develop based on the Kovan test network, and then switch to the main network after the completion of the development. In the project source code we developed, I encapsulated the code for the web3 instance into the getweb3() method of the myUtils.js file for unified calling of the entire project.
Second, get the address, private key, keystore, mnemonic
1. Create an account using web3
To create an account, you need to use the following API of web3.js.
Bind the page that created the account to the interface submitted by the form to the route.
Project source code Github address
Copyright statement: The copyright of the article in the blog belongs to the blogger. It is forbidden to reprint without authorization. Please contact the author (WeChat: lixu1770105) to obtain the consent and indicate the source.
This article address: https://chaindesk.cn/witbook/1/12
Wish code (ChianDesk.CN) – the story of connecting each programmer
Technology upgrade, rapid transformation, please pay attention to WeChat public number: wish code