(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.
L01indicates the minimum compiler version. - The
L03imports all global symbols from "
filenameshould be an actual file name.
L20define a smart contract called
UserStorage. The keyword
contractis 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.
userDatais a state variable for the mapping type. State variables are permanently stored in contract storage. The state variable
userDatamaintains a mapping between
addresstype holds a 20-byte address (Klaytn uses a 20-byte address similar to Ethereum).
L09defines a public function
setthat saves the value
userDatafor the message's sender. The variable
msg.senderis a special variable defined in Solidity that represents the address of the message (i.e., current call) sender. The keyword
publicmeans that the function is part of the contract interface and can be called externally or internally.
L17are 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
L03is excluded in the source file shown above), some examples of compiling the file
UserStorage.solare as follows.
--bin), an abstract syntax tree (by
--ast), and assembly code (by
--asm) as separate files in the