background

After the study of the first two chapters, I believe you have a certain understanding of blockchain. Then, what changes can blockchain technology bring to the Internet?

The nature of blockchain itself is decentralized and immutable, which makes traceability of goods, blockchain invoices, e-money, insurance claims, game exchanges and so on easy to implement

Take Enigma Cat as an example, let’s briefly introduce the implementation of Dapp:

Cryptokitties is a game that runs on the Ethereum platform. Users can raise, sell and breed tamagotchi kittens.

From a commercial perspective, each cat is unique and has “collection value”. In the puzzle cat game, Trands Cat was finally sold at 770,000 RMB. details

From a technical point of view, smart contracts generate “cat” data that users buy through their wallets and bind. Cat A and cat B are “bred”, using an algorithm (seven cat attributes, each 256 cases) to produce cat C. All “cat data” and transaction details are stored in ethereum blocks.

Dapp application development

Message board: engraved user new message, can also see their own history message, forever retained, cannot be tampered with

01 Writing a Contract

  • Pragma Solidity ^0.6.8: Solidity version not higher than 0.6.8
  • Mapping (Address => String) Public Notes: Mapping indicates mapping. The key type is address and the key value is String []
  • Event NewNote(Address, String Note) : After successfully adding notes, events are logged. The client can subscribe to these events through Web3, which can be understood as server callback
  • GetNotesLen () : obtains the total number of voice messages for the user
  • ModifyNote () : Retrieves all messages for the user

02 Writing web3.js interactions

Web3: A set of apis for communicating with Ethereum nodes. It encapsulates the jSON-RPC interface exposed by the nodes and provides multiple language implementations

To put it simply, Web3 is used to obtain node status, obtain account information, call contract, monitor contract events, etc.

Create a Web3 instance

To access an Ethereum contract, you first need to obtain a Web3 instance, and an Ethereum supported browser (such as Mist or MetaMask) will have either the ethereumProvider or Web3.CurrentProvider available. As follows:

Once the Web3 instance is created, we can make interface calls and interactions

To get the message

The new message

Listening to the message

When we add a message, the front-end needs to display this message in real time. Js monitoring is used here, corresponding to the ModifyNote event in our contract:

03 Compilation Contract

Perform truffle compile

04 deployment to Rinkeby

Geth: Ethereum blockchain management client that integrates various Ethereum apis

See we execute command to synchronize Ethereum Rekinby to local

Rinkeby: Ethereum test chain

We execute the command to synchronize Rinkeby locally:

geth –rinkeby –allow-insecure-unlock –syncmode “fast” –rpc –rpcapi db,eth,net,web3,personal –cache=1024 –rpcport 8545 — rpcAddr 127.0.0.1 –rpccorsdomain “*”

Rinkey blockchain schematic:

Complete the configuration in truffle.js

Execute the truffle Migrate command to successfully deploy smart contracts to Rinkeby

Rinkeby deployment, in addition to downloading the full link-local deployment, is also availableInfuraThe deployment of

05 Final Effect

In the end

The original intention of the author was to use the Dapp as a super ledger and embed it into the APP as a core log. However, I was disappointed to find that the operation must be accessed through MetaMask or Ethereum browser

However, Dapp only has a short development period of six years. With the development and expansion of Ethereum, I believe that in the future, it can be better landing and enterprises.

conclusion

Truffle provides a wide variety of project templates and supports Vue and React frameworks. It is recommended for further practice.

Dapp development requires Solidity, web3.js, MetaMask, Truffle, Geth and Rinkeby, in addition to the basic concepts of Ethereum, but keep your mind on the technology and enjoy the fun

References:

Ethereum data synchronization FAQs

Write, compile, deploy, and invoke the contract future edge based on Truffle

Mahesh Murthy: Synchronous blockchain in Ethereum combat