0 foreword
This is my personal podcast series
Second day, set up development environment, with the Node. Js transfer ETH | 5 days to master the etheric fang dApp development
Welcome to our technical discussion
In this chapter, we will learn how to build the Ethereum development environment and run a Demo to transfer ETH through the code.
1 Introduction to development environment
Ethereum development environments fall into three broad categories
- Local Test environment: Local Test Network
- The online test environment includes:
- Ropsten Test Network
- Rinkeby Test Network
- Kovan Test Network
- Goerli Test Network
- Online production environment: Mainnet Network
In general, our project development process is
Local test environment > Online test environment > Production environment
However, this article recommends running quickly through the Ropsten environment and then the local development environment.
The reason is that it’s relatively easy to run through the Ropsten environment with the Ethereum-Demo I provided, and the whole process is close to our normal transfers, so it’s easier to understand how Ethereum works.
2 Ropsten environment quick start
2.1 Generating random Accounts
Visit the mnemonic generation page to generate 12 mnemonic words for test development.
Save randomly generated mnemonics
The first address is Account[0], and the next address is Account[0]
2.2 Receive test ETH
Getting test ETH in the Ropsten network is very convenient, just go to Ropsten Ethereum Faucet and fill in your Ethereum address and the test environment will give you 1ETH.
Enter the address of Account[0] and apply for 1ETH
2.3 registered Infura
Ethereum wallets, such as TrustWallet, Metamask, and MyEtherWallet, can only be connected to the Ethereum network by sending JSON-RPC. So we needed a platform that could provide RPCURL — Infura.
- Go to infura. IO/and register an account
- Keep in mind that
wss://ropsten.infura.io/v3/xxxxx
This string, I’m going to use later. (ENDPOINTS choose ROPSTEN)
2.4 Running Code
I prepared an Ethereum-demo to help you quickly Setup;
Repo address: github.com/netpi/ether… ;
#1
git clone https://github.com/netpi/ethereum-demo.git
#2
cd ethereum-demo
#3
npm install
#Nodejs V8.17.0 ([email protected] currently supports NODE_MODULE_VERSION 57)
Copy the code
Modify the rosten. Config. js file and fill in the mnemonic generated in step 1 and the Rpc-URL obtained in infura. IO.
// ropsten.config.js
module.exports = {
mnemonic: "Your mnemonic.".rpcurl: "The RPC address" / / format such as WSS: / / ropsten infura. IO/ws, accessible infura. IO registration
}
Copy the code
Perform transforEth. Js
In the previous step, the Ropsten environment 1ETH we received should have been received.
Transforeth.js does: Account[0] Transfers 0.01ETH to Account[1]
node transferEth.js
Copy the code
If you see the following information printed on the console, the transfer is successful
{ blockHash: '0x47a243a7d3cf9e1a82d2dfb16bb4db65c248ebd8b5188510ae39be3ddfb80633', blockNumber: 8008669, contractAddress: null, cumulativeGasUsed: 412061, from: '0x15e35634f38f416830aaf09e35b323b516af6d36', gasUsed: 21000, logs: [], logsBloom: '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000', status: true, to: '0x75d60374fd1740d1bcdc033084deaaa57a7d8321', transactionHash: '0x2bf9563c4b094d09ad252bce7ffca5f93438ee0797b3c94be5513e9cc77422d8', transactionIndex: 8 }Copy the code
To see the transfer details, visit roptten.etherscans. IO/search transactionHash
For example: The transactionHash query address where I successfully transferred money in the demo: Click to view
At this point, the Ropsten Test Network runs, and we successfully completed a value transfer of 0.01ETH in the Ethereum Network through the code.
3 Configure the local environment
With the Ropsten environment configured successfully following the steps above, it is easy to configure local development.
3.1 use Ganache
In the local environment, ganache- CLI provides the JSON-RPC service.
Visit www.trufflesuite.com/ganache to download Ganache client;
Run Ganache, configure your mnemonic in Settings –> ACCOUNTS & KEYS, AND click SAVE AND RESTART in the upper right corner
Now you have a native JSON-RPC environment Setup.
3.2 Local environment to run the code
Let’s configure the local environment and copy the RPC SERVER (my default address is http://127.0.0.1:7545).
Modify the local.config.js file
// local.config.js
module.exports = {
mnemonic: "Your mnemonic.".rpcurl: "http://127.0.0.1:7545"
}
Copy the code
Switch the local.config.js file referenced by transferEth
const Web3 = require('web3');
// const config = require('./ropsten.config.js'); // ropsten test network
const config = require('./local.config.js'); // local test network
const HDWalletProvider = require("@truffle/hdwallet-provider");
constmnemonic = config.mnemonic; .Copy the code
Perform tranferEth. Js
node tranferEth.js
Copy the code
Again, seeing the following output indicates success
{ transactionHash: '0xdd6c68c8ac4071fa1cc5f39d0954d8240b8fcf272dd2dca2765c09cfb93180b1', transactionIndex: 0, blockHash: '0x9fadfcf19571d574e03cb410e10c0c817fe76a1e4a1339ff89c2f03afcd5c14e', blockNumber: 1, from: '0x15e35634f38f416830aaf09e35b323b516af6d36', to: '0x75d60374fd1740d1bcdc033084deaaa57a7d8321', gasUsed: 21000, cumulativeGasUsed: 21000, contractAddress: null, logs: [], status: true, logsBloom: '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000 '}Copy the code
3.3 Viewing Local Chain Information using Ganache
In Ganache, the balance of Account[0] becomes 99.99ETH, and the balance of Account[1] becomes 100.01ETH, indicating that the transfer is successful.
We can also view the TX details in Ganache TRANSACTION
So far, we have completed a value transfer in the local environment, and the local environment has been built successfully.
conclusion
Through the practice in this chapter, we successfully run through Ropsten Test Network and Local Test Network, and complete ETH transaction by running the code.
In the next chapter, we will mainly study the knowledge points involved in transferEth. Js in this chapter — the working principle of web3. js and the detailed explanation of the principle of mnemonic words. And smart contract writing, debugging and release.