当前位置:网站首页>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
边栏推荐
- Docking wechat payment (II) unified order API
- If introduced according to the open source framework
- Huawei cloud koomessage is a new marketing weapon in the hot public beta
- [day_010418] delete public string
- [day_030420] find the longest consecutive number string in the string
- Markdown add Emoji expression
- [day06_0423] C language multiple choice questions
- Youwei low code: Brick life cycle component life cycle
- Leetcode:940. How many subsequences have different literal values
- A tool for quickly switching local host files -- switchhosts
猜你喜欢

Markdown add Emoji expression

Introduction to three feasible schemes of grammatical generalization

分布式 | 实战:将业务从 MyCAT 平滑迁移到 dble

RNN recurrent neural network

Matlab 向量与矩阵

【Day05_0422】C语言选择题

Database SQL language practice

【Day04_0421】C语言选择题

Do it yourself smart home: intelligent air conditioning control

基于消防GIS系统的智慧消防应用
随机推荐
Latex merges multiple rows and columns of a table at the same time
Meiker Studio - Huawei 14 day Hongmeng equipment development practical notes 4
nuxt 配置主题切换
[day_010418] delete public string
【Day02_0419】C语言选择题
【Day_05 0422】连续最大和
[specified interval inversion in BM2 linked list]
Mobile web
Embedded sharing collection 14
[pytorch] CNN practice - flower species identification
【Day_04 0421】进制转换
Registration conditions for system integration project management engineer (intermediate level of soft exam) in the second half of 2022
Ganglia安装部署流程
定义方法时为什么使用static关键字
[pytorch] fine tuning technology
C语言进阶——可存档通讯录(文件)
PG Vacuum 杂谈之 auto vacuum
【pytorch】图片增广
Matlab vector and matrix
Xiao He shows his sharp corners and says hello to flutter app