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

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
主站蜘蛛池模板: 南岸区| 永清县| 五莲县| 精河县| 丹凤县| 礼泉县| 通江县| 沧州市| 清原| 金山区| 江达县| 呼玛县| 广元市| 平原县| 乌审旗| 理塘县| 白水县| 吉木萨尔县| 永川市| 大理市| 陕西省| 财经| 阜阳市| 海宁市| 鹤山市| 马鞍山市| 自贡市| 淮滨县| 舒城县| 锡林浩特市| 富宁县| 郁南县| 新竹县| 桐柏县| 蚌埠市| 南昌县| 平凉市| 淮北市| 台州市| 桑植县| 清远市|