1. Understanding Ethereum’s network architectureThe nodes run geth or eth, and they connect to each other through port 30303 for p2p. The protocol running on them is commonly known as the mining protocol, also known as the consensus protocol, which includes several parts, such as broadcasting transactions or messages, synchronizing blocks, etc. Node is a node, often also called geth client or geth server. Each node provides JSONRPC (port 8545) or IPC port to the outside world, and the entire blockchain can be operated through Node, such as querying account information, deploying contracts, etc. Ethereum's wallet is a typical application that operates the blockchain through the IPC interface, but it is not a dApp (distributed app). 2. Ethereum’s dApp ArchitectureAfter understanding the network architecture above, it is easier to understand the architecture of an Ethereum dApp. The bottom layer is the blockchain layer, and you can choose ethereum, testnet or testrpc. The green part will be quite different depending on the framework you choose, but the basic principle is the same, that is, the framework should provide the function of operating the blockchain interface, preferably a complete protocol stack. Since the official web3.js is a complete RPC protocol interface based on node.js, it is more natural to implement a Web Framework based on JS. The more well-known ones are truffle, and the official recommendation is meteor. But in theory, any framework that provides a protocol for interacting with the Blockchain (i.e. connecting to the 8545 RPC port) can be used to implement dApp, and more than 80% of it is traditional WEB or mobile application development content. 3. Environmental PreparationOperating system Ubuntu 16.04 AMD64 Step 1: Install rvm/ruby/rails #gpg –keyserver hkp://keys.gnupg.net –recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 #\curl -sSL https://get.rvm.io | bash #rvm install 2.3 #gem install bundler #gem install rails Step 2: After the above steps, Rails 4.2.x should have been installed in the system. Since there are not many developers using Ruby in China, the limited group should have the basic skills of installing the environment. In addition, this article does not focus on the installation and use of Rails. If you have any questions, you can search Baidu or Google. Check the environment to ensure that Rails runs correctly. $ rails –v Step 3: Create a rails project $ rails new helloworld step4: install nodejs $ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - $ sudo apt-get install -y nodejs $ export PATH=/usr/bin:$PATH step5: Install testrpc $ npm install –g ethereumjs-testrpc step5b: Install geth/eth. This step is optional. If you just want to experience operating the blockchain through rails, installing testrpc is enough. $ bash <(curl https://install-geth.ethereum.org -L) $ bash <(curl https://install-eth.ethereum.org -L) step6: Install solc /This step can also be installed through npm, so I won’t go into details. $ sudo add-apt-repository ppa:ethereum/ethereum $ sudo apt-get update $ sudo apt-get install solc At this point, a blockchain test development environment is basically OK. 4. Integrate the ethereum-ruby Gem into the project Step 1: Create a new project $ rails new helloworld Step 2: Modify Gemfile and add ethereum gem 'ethereum' Step 3: Run bundle install $ bundle install Step 4: Run testrpc Step 5: Start the rails console $ rails c And establish a link with testrpc on the console as follows: Step 6: Create a simple smart contract $ mkdir contracts $ vi contracts/Helloworld.sol contract Helloworld { mapping (address => bool) public myMapping; function register(address _a, bytes32 _b) { } } Step 7: Deploy and compile on the console > con=Ethereum::Initializer.new 'contracts/Helloworld.sol', c The results are as follows: > con=Ethereum::Initializer.new 'contracts/Helloworld.sol', c If you switch to the testrpc window at this time, you can find that you have received a compileSolidity command: |
<<: Can Bitcoin overcome its biggest obstacle — decentralization — and achieve the best governance?
Headlines Zhao Changpeng: Binance is about to lau...
There is a short horizontal line at the base of t...
Marriage is of vital importance to women. In phys...
What are the characteristics of a caring man? Peo...
Nostrils pointed upwards, straightforward persona...
Author | Hashipi Analysis Team...
What do women’s triangular eyebrows represent? Pe...
The most attractive face of a man to women Every ...
The face of a lewd woman who cheated on her husba...
Making small payments through the Internet has gr...
How to tell if a woman's husband is handsome ...
The price of Bitcoin fell again in the Asian sess...
Now let’s turn to the more pressing issue: how th...
Bitcoin fully recovered from the 2021-22 decline ...
This means that the ETH2.0 Phase0 and Staking tha...