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

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
主站蜘蛛池模板: 顺平县| 九寨沟县| 武城县| 凤山县| 田林县| 平罗县| 青河县| 会东县| 双流县| 新余市| 乌拉特中旗| 时尚| 维西| 宁陵县| 柏乡县| 岫岩| 全州县| 安徽省| 彰化市| 偃师市| 壶关县| 靖西县| 哈密市| 溧阳市| 洪江市| 阳城县| 酉阳| 襄樊市| 永寿县| 新沂市| 吴川市| 乌鲁木齐市| 松潘县| 措美县| 天祝| 宝山区| 镇赉县| 微山县| 炎陵县| 信丰县| 陵川县|