当前位置:网站首页>09 eth smart contract
09 eth smart contract
2022-07-26 06:23:00 【Preys】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
Catalog
Two 、 The code structure of smart contracts
3、 ... and 、 How one contract calls a function in another contract
Four 、 A special kind of function in smart contract
5、 ... and 、 The creation and operation of smart contracts
Nine 、 The block information that can be obtained by the contract
Ten 、 Call information that can be obtained by the contract
11、 ... and 、 Address type in the contract
Preface
I saw teacher Xiao Zhen of Peking University today 《 Blockchain Technology and application 》 Public class , Have a great harvest , Write a blog here to take notes , Deepen the impression , If there is something wrong , Welcome more .
One 、 What is a smart contract ?
- A smart contract is a piece of code that runs on a blockchain , The logic of the code defines the contract content
- The account of smart contract saves the current running state of the contract
- balance: Current balance
- nonce: Number of transactions
- code: Contract code
- storage: Storage , The data structure is a tree MPT
3. Solidity Is the most commonly used language for smart contracts , Grammatically with JavaScript Very close to
Two 、 The code structure of smart contracts

This graph shows solidity Code structure of ( because CSDN The picture of cannot be elongated , The picture is not clearly shown , I'm sorry )
- The first line states solidity Version number of , Different versions solidity There are some differences in grammar
- solidity Is an object-oriented programming language , there contract Is similar to the Java Medium class
- solidity It's a strongly typed language , The defined state variables are related to C++ These languages are relatively close , In the middle of address The type is solidity Unique in
3、 ... and 、 How one contract calls a function in another contract

- In the contract B By creating contracts A To call A The function in

- Using this method can prevent this call from being rolled back when an error occurs in calling other contracts
Four 、 A special kind of function in smart contract

- When you need to fallback When the function has the function of accepting transfer , Then add payable keyword
5、 ... and 、 The creation and operation of smart contracts

6、 ... and 、 Gas

- Gasoline is the extra transaction fee you need to pay when you start a transaction , That is to say, you want miners to help you pack your deal , Or you need to pay for executing a smart contract transaction
- Each transaction will be charged for gasoline according to the resources consumed in the execution of the transaction , Every transaction has a gaslimit, That is, the gasoline cost of the transaction set by the initiator , When the transaction is executed, it will be fully deducted gaslimit Gasoline cost of different sizes , Then return the remaining gasoline expenses according to the actual implementation , If the gasoline cost is not enough, it will cause rollback , But the deducted gasoline fee will not be refunded
7、 ... and 、 Error handling

- Transactions in Ethereum are atomic , A transaction is either fully executed or not executed , There will be no half implementation , This transaction includes both transfer transactions and smart contract transactions , In other words, if a smart contract fails halfway through its execution , It will cause the rollback of the whole transaction
8、 ... and 、 Nested calls

- In some cases, on the surface, you don't call functions , For example, you initiate a transfer , But if this collection account is a contract account, it will be different , Your operation may call the contract fallback function
Nine 、 The block information that can be obtained by the contract
Ten 、 Call information that can be obtained by the contract
11、 ... and 、 Address type in the contract
- The semantics of these member functions are different from our intuitive feelings , for example :address.banlance() This function is to check the balance in this address , but address.transfer(123456) It means that the contract account transfers money to this address 123456wei
summary
Smart contract is a feature of Ethereum and a very important part of Ethereum
边栏推荐
- 【Day02_0419】C语言选择题
- 【保姆级】包体积优化教程
- BigDecimal becomes negative
- YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
- [day_060423] convert string to integer
- 【Day_05 0422】统计回文
- 基于消防GIS系统的智慧消防应用
- PG Vacuum 杂谈之 auto vacuum
- Niuke network: TOPK problem of additive sum between two ordinal groups
- Servlet cannot directly obtain JSON format data in request request
猜你喜欢

输入5个学生的记录(每条记录包括学号和成绩), 组成记录数组, 然后按照成绩由高到低的次序输出. 排序方法采用选择排序

JVM class loading and GC garbage collection mechanism

RNN recurrent neural network

Code runner for vs code, with more than 40million downloads! Support more than 50 languages

Excitation method and excitation voltage of hand-held vibrating wire vh501tc acquisition instrument

flex布局
![[(SV & UVM) knowledge points encountered in written interview] ~ phase mechanism](/img/19/32206eb6490c2a5a7a8e746b5003c1.png)
[(SV & UVM) knowledge points encountered in written interview] ~ phase mechanism

【保姆级】包体积优化教程

PHP 多任务秒级定时器的实现方法

Multi target detection
随机推荐
Map集合继承结构
[1]数学建模基础入门知识
Youwei low code: Brick life cycle component life cycle
C语言进阶——可存档通讯录(文件)
What is the concept and purpose of white box testing? And what are the main methods?
【Day_02 0419】倒置字符串
Knowledge precipitation I: what does an architect do? What problems have been solved
Database SQL language practice
【BM2 链表内指定区间反转】
JVM class loading and GC garbage collection mechanism
【pytorch】微调技术
PG vacuum auto vacuum
【pytorch】图片增广
Multi target detection
A tool for quickly switching local host files -- switchhosts
Ganglia installation and deployment process
Niuke network: TOPK problem of additive sum between two ordinal groups
Taobao pinduoduo Tiktok 1688 Suning taote jd.com and other keyword search commodity API interfaces (keyword search commodity API interface, keyword search commodity list interface, classification ID s
Calling mode and execution sequence of JS
nuxt 配置主题切换