- Ethereum Smart Contract Development
- Mayukh Mukhopadhyay
- 390字
- 2021-06-24 19:23:53
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:
- 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
- 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:

Figure 3.2: Remix—Solidity IDE
- 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
- 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
- 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
- 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
- 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
推薦閱讀
- 數(shù)學不簡單:從《最強大腦》發(fā)現(xiàn)思維樂趣
- Introduction to Blockchain and Ethereum
- Hands-On Blockchain Development in 7 Days
- 數(shù)學可以很有趣:科學新悅讀文叢(套裝全5冊)
- 圖解博弈論
- 妙趣橫生博弈論:事業(yè)與人生的成功之道(白金版)
- Origin 9.0科技繪圖與數(shù)據(jù)分析超級學習手冊
- MATLAB矩陣分析和計算
- 文化偉人代表作圖釋書系:算術研究
- 趣味魔方:一學就會的魔方秘笈
- 怎樣解題:數(shù)學競賽攻關寶典(第3版)
- 愛情數(shù)學(TED 思想的力量系列)
- 博弈論與信息經(jīng)濟學:PBL教程
- 高等數(shù)學習題全解與學習指導(下冊)
- 基于ANSYS的信號和電源完整性設計與分析(第2版)