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 ...
随机推荐
- net core 随笔
UseApplicationInsights 这个有用到azure 才有用, 平时没用的话可以去掉. 遥测. 上下文指的是 进程间占有的资源空间. 当一个进程时间片到了或者资缺的时候就会让出CPU ...
- JAVA基础50题
package package0530; import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;imp ...
- vue项目中,使用vue-awesome-swiper插件实现轮播图
一.安装 npm install vue-awesome-swiper 二.项目中引入 import 'swiper/dist/css/swiper.css'import {swiper,swiper ...
- pytest自动化7:assert断言
前言:assert断言就是将实际结果和期望结果做对比,符合预期结果就测试pass,不符合预期就测试failed. 实例1:简单断言 实例1优化版--增加异常信息文字描述 异常断言 excinfo 是一 ...
- Javascript 数组相关操作
数组排序问题: sort() arr.sort() 可以直接进行排序,但是排序的方式是按unicode 顺序而来,比如1,1000,200,这个顺序不是我们想要的结果: 所以有了另一种方法,针对num ...
- Windows 2008 asp.net 配置
目录 1. 前言.. 32. 部署环境.. 32.1 服务器环境信息.. 33. 磁盘阵列配置.. 44. 安装操作系统.. 45. 安装软件. ...
- Linux系统KVM虚拟化技术
在公司工作时出现了这样一个需求:需要在一台服务器中安装两个系统,分别部署不同的服务,设置不同的系统时间,并且两个系统之间可以互相通讯.在网上查询相关资料后,决定通过KVM实现该功能,现将步骤记录如下. ...
- iOS 跨App数据共享
http://www.jianshu.com/p/169e31cacf42 http://www.jianshu.com/p/7f8472a97aa6 https://segmentfault.com ...
- 添加PROPAGATION_REQUIRES_NEW 事务没有产生作用
最近在做事务添加时 发现自己的事务没有新建,上网查到 仅用作收藏. 其二 注意 事务的注解 应该在 内层的事务上面 一.描述Spring遇到嵌套事务时,当被嵌套的事务被定义为“PROPAG ...
- select 下拉选择自动到textarea框
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...