知识点

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;
}

ref

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

ref

ref

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

-- 参数不对

good REF

smart contract 知识点的更多相关文章

  1. Smart Contract - Hello World

    [编写Smart Contract] 1.包含头文件. #include <eosiolib/eosio.hpp> #include <eosiolib/print.hpp> ...

  2. ethereum/EIPs-1271 smart contract

    https://github.com/PhABC/EIPs/blob/is-valid-signature/EIPS/eip-1271.md Standard Signature Validation ...

  3. Using APIs in Your Ethereum Smart Contract with Oraclize

    Homepage Coinmonks HOMEFILTER ▼BLOCKCHAIN TUTORIALSCRYPTO ECONOMYTOP READSCONTRIBUTEFORUM & JOBS ...

  4. Truffle Smart Contract Error: Invalid number of parameter

      I followed the tutorial of quorum with truffle: https://truffleframework.com/tutorials/building-da ...

  5. 区块链学习5:智能合约Smart contract原理及发展历程科普知识

    ☞ ░ 前往老猿Python博文目录 ░ 一.智能合约的定义 通俗来说,智能合约就是一种在计算机系统上,当一定条件满足的情况下可被自动执行的合约,智能合约体现为一段代码及其运行环境.例如银行信用卡的自 ...

  6. 【翻译】A Next-Generation Smart Contract and Decentralized Application Platform

    原文链接:https://github.com/ethereum/wiki/wiki/White-Paper 当中本聪在2009年1月启动比特币区块链时,他同时向世界引入了两种未经测试的革命性的新概念 ...

  7. 【阿菜Writeup】Security Innovation Smart Contract CTF

    赛题地址:https://blockchain-ctf.securityinnovation.com/#/dashboard Donation 源码解析 我们只需要用外部账户调用 withdrawDo ...

  8. the security of smart contract- 1

    https://blog.zeppelin.solutions/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05 这个 ...

  9. Smart Contracts

    A smart contract is a computer code running on top of a blockchain containing a set of rules under w ...

随机推荐

  1. CEPH集群操作入门--配置

      参考文档:CEPH官网集群操作文档   概述 Ceph存储集群是所有Ceph部署的基础. 基于RADOS,Ceph存储集群由两种类型的守护进程组成:Ceph OSD守护进程(OSD)将数据作为对象 ...

  2. Linux 设备驱动之字符设备

    参考转载博客:http://blog.chinaunix.net/uid-26833883-id-4369060.html https://www.cnblogs.com/xiaojiang1025/ ...

  3. 汉明码(Hamming)编码与纠错原理

    一 汉明码的编解码说明 (一)编码 Hamming(12,8) N=12,表示编码后的比特长度 K=8,待编码数据的比特长度 R=N-K=4,校验位的比特长度 D=3 汉明距离:相邻行之间不同比特数据 ...

  4. Tensorflow实战系列之二:

    还没想好,可能是人脸检测或者物体检测,或者加上动态检测~~

  5. (转) java 通过 jdbc 链接 ms sql server 中出现 "no suitable driver for ..."

    原文连接 : http://blog.csdn.net/stewen_001/article/details/19553173/ 前面是 基本操作步骤,按照原博主的方式进行操作即可...() 这里是需 ...

  6. C++笔记之关键字explicit

    在C++中,explicit关键字用来修饰类的构造函数,被修饰的构造函数的类,不能发生相应的隐式类型转换,只能以显示的方式进行类型转换. explicit使用注意事项: explicit 关键字只能用 ...

  7. 搭建NTP服务集群、高可用

    1.原理 Keepalived 的作用是检测后端服务器的状态,如果有一台服务器死机,或工作出现故障,Keepalived 将检测到,并将有故障的服务器从系统中剔除.当服务器工作正常后 Keepaliv ...

  8. ARM内核单片机Bootloader中断向量重定位问题

    Bootloader中断向量重定位问题 1.Bootloader程序在内核Cortex-M0+内核中运行时需要进行地址跳转执行应用程序主程序,此时就涉及到了中断向量重定位问题,以下截图为单片机启动文件 ...

  9. JavaScript中call和apply方法的使用

    acvaScript中的call()方法和apply()方法,在某些时候这两个方法还确实是十分重要的.1. 每个函数都包含两个非继承而来的方法:call()方法和apply()方法.2. 相同点:这两 ...

  10. 网络原因导致的 spring cloud config 读取git上的配置文件时报错:Cannot clone or checkout repository

    今天在公司使用spring cloud config搭建配置中心的时候,出现了读取不到git库的问题:Cannot clone or checkout repository.在网上百度,前面几个答案都 ...