or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Solidity
Solidity Compiler
converts object-oriented, high-level language to implement contract templates into simple binaries, assembly and various other related metadata
pragma solidity
(see all compiler versions)
Simple
Coin
Contract TemplateContract Template
define State Variables
Are like a single slot in a database.
X
is of typeaddress
(=160-bit value that does not allow any arithmetic operations).Contract Template
define Functions
set
andget
view as part of public interfacethese functions can be used by other
acounts
to set/modify/alter or get/query/retrieve a value of a state variable.Contract Template
Access Modifier
public
keyword auto-generates a read access function for other accountsContract Template
mapping
data typemap key of type1 to value of type2 for later lookup
All keys by default map to all zeros byte-representation values and listing all is not possible
Contract Template
mapping
data typemap key of type1 to value of type2 for later lookup
Using
public
on amapping
auto-generates a more complex read access function for other accounts to query the balance of a single accountbalances(minter)
=>123
Contract Template
global variables
Contract Template
constructor
Constructor function runs only once when the contract is published
Contract Template
declare events
declares an
event
which can be emitted and allows clients (e.g. dapps) to reactContract Template
emit events
Event listeners receive emitted arguments
Dapp
event listening
Dapp
calling functions
Contract Template
require
guardIf
"1st argument"
ofrequire
isfalse
,execution ends and all state and ether balance changes are reverted.
Demo Time
copy to open in play-ed
Simple
Ballot
Contract TemplateContract Template
struct
type &bool
type & NatSpecbool
can only store one of two values at a time (true
orfalse
)Contract Template
bytes32
typeContract Template
"struct array"
typeContract Template
Reference Types
memory
keyword used for "reference types"Contract Template
for loop
,"struct object"
andarray.push
Contract Template
Reference Types
storage
keyword used for "reference types"Contract Template
"named returns" and "function re-use"
Demo Time
copy to open in play-ed
Thank you
questions?
connect with us
twitter/telegram
chat