(require)
means that the line is required for any Solidity source file while (optional)
indicates that the line is not always needed. The symbol Ln:
is not part of the Solidity code and is included here only to show the line numbers. Please do not include these symbols in source code intended for real use.//
) are comments rather than code; they are used to annotate and explain the code. The compiler ignores comments.pragma
statement in L01
indicates the minimum compiler version. - The import
statement in L03
imports all global symbols from "filename
". filename
should be an actual file name.L05
- L20
define a smart contract called UserStorage
. The keyword contract
is located before the contract name and declares that the code represents a smart contract. Contracts in Solidity are similar to classes in object-oriented languages. Each contract can contain declarations for state variables, functions, function modifiers, events, struct types and enum types. Furthermore, contracts can inherit from other contracts. The example code contains one contract definition, but a single Solidity file may contain more than one contract definition.L07
, userData
is a state variable for the mapping type. State variables are permanently stored in contract storage. The state variable userData
maintains a mapping between address
and a uint
value. The address
type holds a 20-byte address (Klaytn uses a 20-byte address similar to Ethereum).L09
defines a public function set
that saves the value x
in userData
for the message's sender. The variable msg.sender
is a special variable defined in Solidity that represents the address of the message (i.e., current call) sender. The keyword public
means that the function is part of the contract interface and can be called externally or internally.get
in L13
and getUserData
in L17
are declared with view
, which means that the functions promise not to modify any state variable. Their declarations include returns (uint)
, which implies that they return a uint
value.UserStorage.sol
(L03
is excluded in the source file shown above), some examples of compiling the file UserStorage.sol
are as follows.--bin
), an abstract syntax tree (by --ast
), and assembly code (by --asm
) as separate files in the output
directory.--optimize
flag.