Solidity 编译运行

我们可以使用在线 Solidity 开发工具 Remix IDE 编译和运行 Solidity 程序。

remix

 

1.  编写代码

在File explorers 选项卡下,新建一个SolidityTest.sol 文件,代码如下:

// SPDX-License-Identifier: SimPL-3.0
pragma solidity ^0.7.0;

contract SolidityTest{
    function helloWorld() public pure returns(string memory) {
        return "Hello World";
    }
}

 

2. 编译代码

在 Compiler 选项卡下,单击 Compile 按钮,开始编译。

 

3. 部署合约

在 Run 选项卡下,单击 Deploy 按钮进行部署。

在下方出现,已部署合约 SOLIDITYTEST AT 0xd9145CCE52D386f254917e481eB44e9943F39138。

 

4. 运行合约

在 Run 选项卡下,选择 SOLIDITYTEST AT 0XD 下拉,会出现 helloWorld 按钮。 单击 helloWorld 按钮,将显示合约执行结果。

输出结果为:

Hello World

Solidity 支持 c 风格和 c++ 风格的注释。//之后到行尾的文本,都被看作注释,编译器忽略此内容/* 与 */ 之间的文本被看作注释, 编译器忽略此内容示例注释示例。function getResul ...