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 ...
随机推荐
- 外网win10 64位环境下 为内网win7 32位安装三方包的最靠谱手段:python64位、32位全安装。
经过一周的各种折磨,如题.以下是我的经验和教训. 我的外网是win10 64位,内网环境win7 32位.由于未知原因,anaconda无法安装!!! 其实最靠谱的安装三方包的还是whl包.但是很有可 ...
- input 特殊字符限制
ng-pattern="/^[A-Za-z0-9_,\.\u4e00-\u9fa5\s]+$/"
- 背景图片利用backgrond-posintion属性实现不同形式的分割
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Win10调整MTU值
VPN连接后出现可以ping通google.com但是网页打不开的情况,需要修改MTU值,方法如下:用管理员身份运行cmd列出当前各网络的mtu值C:\Windows\system32>nets ...
- Python 3 基本操作列举
1.字符串 2,列表 3.random库 计算机产生的随机数都是有一个种子开始的伪随机序列,相同的随机种子产生相同的伪随机数序列. >>> random.seed(10) >& ...
- 基本矩张量与strike.dip.rake的对应
basefp1=[ ]; M(,:)=[ ]; basefp2=[ -];M(,:)=[ - ]; basefp3=[ ];M(,:)=[ ]; basefp4=[ -];M(,:)=[ ]; bas ...
- SharePoint Framework 基于团队的开发(五)
博客地址:http://blog.csdn.net/FoxDave 升级SharePoint Framework项目 部署SharePoint自定制解决方案到生产环境并不意味着生命周期的结束,因为还有 ...
- 学号 20175223 《Java程序设计》第9周学习总结
目录 教材学习内容总结 教材学习中的问题和解决过程 1. 输出文件时过多输出. 代码调试中的问题和解决过程 1. 问题:费马素性检验程序. [代码托管] 学习进度条 参考资料 目录 教材学习内容总结 ...
- [RESTful] 项目设计实践
有以下的项目需求 用户登录.注册 文章发表.编辑.管理.列表 一.资源路径 /users./articles 二.HTTP动词 GET.POST.DELETE.PUT 三.过滤信息 文章的分页筛选 四 ...
- session_id() , session_start(), $_SESSION["userId"], header("Location:homeLogin.php"); exit 如果没有登录, 就回登录页
if(!session_id()) session_start(); header("Content-type:text/html;charset=utf-8"); if (emp ...