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 ...
随机推荐
- 分享:五个非常有用的WP插件
一全老师(www.yiquanseo.com)认为非常有用的几款WP插件,用WordPress做站的可以看下,估计你很可能用得到! 第一款WooCommerce Page Builder: 这款插件是 ...
- open还是codecs.open区别
>>> fr = open('test.txt','a')>>> line1 = "我是一道光">>> fr.write(li ...
- date clock
设置Linux系统时间:date -s "2017-06-22 15:44:30" 自定义时间显示格式:date "+%Y-%m-%d %H:%M:%S" 查 ...
- vue实现pc端上拉加载功能,不兼容移动端
所用插件:Mock.js 这个只用到它简单的功能,拦截ajax请求. vue和axios,vue基础知识请看文档. axios类似于jquery的ajax方法. 以下是是该功能所有代码,其中mock的 ...
- Python PIL
Python PIL PIL (Python Image Library) 库是Python 语言的一个第三方库,PIL库支持图像存储.显示和处理,能够处理几乎所有格式的图片. 一.PIL库简介 1. ...
- java跨域
在我们开发当中 经常会碰见跨域问题 今天我来说下 我在工作撞见的跨域: 一.首先我们要了解跨域存在的原因 1.浏览器限制 2.跨域(域名,端口不一样都是跨域) 3.XHR(XMLHttpReques ...
- OpenGL 3D旋转的木箱
学习自: https://learnopengl-cn.github.io/01%20Getting%20started/08%20Coordinate%20Systems/#3d 0,首先添加glm ...
- 18-11-05ie 热键的使用
IE浏览器快捷键大全 更新:2013-04-01 17:05 | 标签:快捷键 一般快捷键F11打开/关闭全屏模式 TAB循环的选择地址栏,刷新键和当前标签页 CTRL+F在当前标签页查询字或短语 C ...
- Qt设置创建部分半透明,上面控件不透明
//头文件#pragma once #include <QWidget> #include "ui_widgetFullAD.h" class widgetFullAD ...
- 实现鼠标悬停,div勾画div边框的动画
鼠标悬浮,边框div边框的动画样式,效果图如下: 首先定义div及其样式: <style> .show { width:300px; height:200px; border:1px so ...