Solidity 是一门面向合约的、为实现智能合约而创建的高级编程语言。这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的目的是能在以太坊虚拟机(EVM)上运行。
pragma solidity >=0.4.0 <0.6.0;
contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}
第一行的pragma
指令是指定源代码所使用的编译器版本,示例程序的版本为Solidity version 0.4.0及以上版本编写的,但不包括version 0.6.0及以上版本。
也可以使用符号^
:
pragma solidity ^0.5.0; //表示不超过0.5.0版本
abstract | after | alias | apply | auto | case |
---|---|---|---|---|---|
catch | copyof | default | define | final | immutable |
implements | in | inline | let | macro | match |
mutable | null | of | override | partial | promise |
reference | relocatable | sealed | sizeof | static | supports |
switch | try | typedef | typeof | unchecked |