smart contract 知识点
知识点
memory vs storage vs stack
storage , where all the contract state variables reside. Every contract has its own storage and it is persistent between function calls and quite expensive to use.
memory , this is used to hold temporary values. It is erased between (external) function calls and is cheaper to use.
stack , which is used to hold small local variables. It is almost free to use, but can only hold a limited amount of values.
There are defaults for the storage location depending on which type of variable it concerns:
state variables are always in storage
function arguments are in memory by default
local variables of struct, array or mapping type reference storage by default
local variables of value type (i.e. neither array, nor struct nor mapping) are stored in the stack
constanst vs view vs pure
- constant: Starting with solc 0.4.17, constant is deprecated in favor of two new and more specific modifiers.
- View: This is generally the replacement for constant. It indicates that the function will not alter the storage state in any way.
- Pure: This is even more restrictive, indicating that it won't even read the storage state.
function returnTrue() public pure returns(bool response) {
return true;
}
require vs assert vs revert vs throw(if)
简化:
require() and revert() will cause refund the remaining gas
assert() will used up all the remaining gas
Use require() to:
- generally it will be used at the begining of a function, validate user inputs : such as invalid input
- should be used more often
use assert() to :
- prevent condition that should never, ever be possible : such as fatal error
- generally it will be used at the end of a function
- should be used less often
revert() it was said that revert can handle more complex logic.(emit that, I think we should use require() instead)
throw : deprecated
todo:
lib
use external source(local sol or git)
call from another contract
msg.sender what's in msg
ide 调试
string compare
return struct
testing
more useful ref:
best practise
FAQ about Error
Error: VM Exception while processing transaction: invalid opcode
-- out of index
Error: Invalid number of arguments to Solidity function
-- 参数不对
smart contract 知识点的更多相关文章
- Smart Contract - Hello World
[编写Smart Contract] 1.包含头文件. #include <eosiolib/eosio.hpp> #include <eosiolib/print.hpp> ...
- ethereum/EIPs-1271 smart contract
https://github.com/PhABC/EIPs/blob/is-valid-signature/EIPS/eip-1271.md Standard Signature Validation ...
- Using APIs in Your Ethereum Smart Contract with Oraclize
Homepage Coinmonks HOMEFILTER ▼BLOCKCHAIN TUTORIALSCRYPTO ECONOMYTOP READSCONTRIBUTEFORUM & JOBS ...
- Truffle Smart Contract Error: Invalid number of parameter
I followed the tutorial of quorum with truffle: https://truffleframework.com/tutorials/building-da ...
- 区块链学习5:智能合约Smart contract原理及发展历程科普知识
☞ ░ 前往老猿Python博文目录 ░ 一.智能合约的定义 通俗来说,智能合约就是一种在计算机系统上,当一定条件满足的情况下可被自动执行的合约,智能合约体现为一段代码及其运行环境.例如银行信用卡的自 ...
- 【翻译】A Next-Generation Smart Contract and Decentralized Application Platform
原文链接:https://github.com/ethereum/wiki/wiki/White-Paper 当中本聪在2009年1月启动比特币区块链时,他同时向世界引入了两种未经测试的革命性的新概念 ...
- 【阿菜Writeup】Security Innovation Smart Contract CTF
赛题地址:https://blockchain-ctf.securityinnovation.com/#/dashboard Donation 源码解析 我们只需要用外部账户调用 withdrawDo ...
- the security of smart contract- 1
https://blog.zeppelin.solutions/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05 这个 ...
- Smart Contracts
A smart contract is a computer code running on top of a blockchain containing a set of rules under w ...
随机推荐
- Linux内核数据结构之kfifo详解
本文分析的原代码版本: 2.6.24.4 kfifo的定义文件: kernel/kfifo.c kfifo的头文件: include/linux/kfifo.h kfifo是内核里面的一个First ...
- P5016 龙虎斗 题解
这题真是*到家了QAQ 我在考场上调了将近75min,总算过了大样例. 首先,我们可以简化这一题,这道题的本质就是让我们找出一个点p2,往那个点上面加上s2个单位的重量,使得以m为中的两边的权值和的差 ...
- 20175224 2018-2019-2 《Java程序设计》第三周学习总结
教材学习内容总结 编程语言发展的几个阶段 面向机器语言 面向过程语言 面向对象语言 封装性 继承性 多态性 类 类是Java程序的基本要素,一个Java应用程序就是由若干个类所构成的. 类是Java语 ...
- VsCode删除多行操作
1.下图是我们的文件 我想要一次性删除"how to delete this line" 所在的所有行,而其他行不删除 操作步骤 鼠标移动到 "how"上面,单 ...
- 基于java代码的springmvc配置
在我的印象中,开发一个web项目首选当然是springmvc,而配置springmvc无非就是web.xml里配置其核心控制器DispatcherServlet.然后把所有的请求都交给它处理,再配个视 ...
- 解决getElementsByClassName()在IE8下的兼容问题
getElementsByClassName,这个方法让我们可以通过 class 属性中的类名来访问元素,但是IE9 以下的浏览器不支持 .为解决这个问题,我们写一个兼容函数 getByClass() ...
- io 的一些简单说明及使用
io 流简述: i->inputStream(输入流) o->outputStream (输出流) IO流简单来说就是Input和Output流,IO流主要是用来处理设备之间的数据传输, ...
- Vue中transition和animation的使用
一:二者的对比 1.动画循环就用animation.在animation中有一个animation-iteration-count属性可以定义循环次数.transition是执行一次以后就不会执行,但 ...
- vue-router 重难点总结笔记
1,使用动态路由配置的(如:‘:id’),可以在this.$router.params.id获得. 官网例子: 模式 匹配路径 $route.params /user/:username /user/ ...
- input()和print()函数同时输入输出多个数据--python3
使用input()和print()函数同时输入输出多个数据,需要空格分割输入信息 #!/usr/bin/python3#-*- conding:utf-8 -*- name, age, QQ = in ...