官术网_书友最值得收藏!

A smart contract in seven lines of code

In this section you will learn to code your first smart contract in just seven lines of code (Loc), no hidden terms and conditions. And did I say that you do not need any special software, apart from your web browser, or to spend any real ethers from your pocket? Let's see. I am using Windows 7 (64 bit OS) and a Google Chrome browser:

  1. Open your Google Chrome browser and type remix solidity in Google, as show in Figure 3.1:
Figure 3.1: Google search for remix solidity online compiler
  1. Click the highlighted link in Figure 3.2. You can also type the following in your browser URL box to get to the website directly: http://remix.ethereum.org:

The present remix ethereum webpage is going through rapid changes and version increments. Meanwhile, and older yet stable version is provided to Solidity users for practice in the following link:

https://yann300.github.io/remix04/

Figure 3.2: Remix—Solidity IDE
  1. Click the plus sign as marked in Figure 3.3 to create a new untitled Solidity (.sol) file.
Figure 3.3 Untitled Solidity file in remix IDE

Rename it HelloWorld.sol and confirm the renaming, as shown in Figure 3.4:

Figure 3.4: Untitled.sol renamed to HelloWorld.sol
  1. Write the following seven lines of code in the HelloWorld.sol file, as shown in Figure 3.5:
Figure 3.5: HelloWorld.sol

Choose the JavaScript VM Environment option, as shown in Figure 3.6:

Figure 3.6: JavaScript VM acting as a blockchain simulator
  1. Click the Create button, as highlighted in Figure 3.7. Voila! You just created your smart contract. The only caveat is that we would be simulating it on our local machine using in-memory, which mimics an Ethereum blockchain:
Figure 3.7: Our first smart contract of 368 bytes
  1. To execute this contract, we press that myFirstHelloWorld button, as shown in Figure 3.8. We get the desired output: Hello World !
Figure 3.8: Execution of myFirstHelloWorld function using a smart contract
  1. We can also explore the byte codes, which are generated as a result of this smart contract execution, by pressing the Launch debugger | Instructions or just by clicking the Contract details (bytecode, interface etc) link. Figure 3.9 depicts the 368 bytes of virtual machine code generated by the hello world smart contract execution:
Figure 3.9: 368 bytes [000 to 367] of machine code for Hello World smart contract
主站蜘蛛池模板: 大港区| 布拖县| 乐昌市| 汪清县| 沙田区| 蓬安县| 辽源市| 北京市| 桂林市| 德惠市| 开平市| 丹东市| 无棣县| 泰兴市| 巩留县| 通城县| 绥阳县| 九江市| 伊吾县| 米脂县| 永济市| 苗栗县| 永新县| 永福县| 乃东县| 塘沽区| 宣武区| 阿拉善右旗| 新和县| 洮南市| 静宁县| 裕民县| 琼海市| 溧水县| 孝感市| 江达县| 弥勒县| 肇州县| 昌黎县| 资阳市| 德化县|