知识点

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. 异常 - Error / Checked Exception / Runtime Exception

    https://www.cnblogs.com/loveis715/p/4596551.html

  2. 记一次JDK升级带来的连环反应

    公司之前有个很久以前的小项目,页面用到了flash. 现在要去掉flash, 前端使用公司自己开发的框架来展示数据, 使用该框架后台要引用一个jar包封装数据传递给前台. 但该框架是jdk1.8编译的 ...

  3. xslt 2.0 分组

    把数据拆成200个一组 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet vers ...

  4. css 清楚浮动的几种方式

    方法一: 使用clear属性的空元素 <div style="clear:both;"></div> 方法二:使用overflow属性 给浮动的元素容器添加 ...

  5. 原生JS和jQuery操作DOM的区别小结

    一.Js原生对象和jQuery实例对象的相互转化: (1).原生JS对象转JQ对象: $(DOM对象); (2). JQ对象转原生JS对象: $(DOM对象).get(index); //注意区分eq ...

  6. kaptcha生成java验证码

    kaptcha工作的原理是调用 com.google.code.kaptcha.servlet.KaptchaServlet,生成一个图片.同时将生成的验证码字符串放到 HttpSession中. 1 ...

  7. WPF自定义用户控件不显示

    1,Themes\Generic.xaml最好不要更名 "Generic.xaml"这个名称并非偶然通过上面的叙述,你可能会有冲动将Generic.xaml中的Style代码剪切出 ...

  8. CentOS7突然出现无法连接网络的情况--VM下

    转自:https://blog.csdn.net/xzm5708796/article/details/83757372 突然出现VM内安装的centos7系统无法通过外部进行连接1.登陆到虚拟机上查 ...

  9. canvas 添加线和删除线 及获取相关位置信息源码

    其他相关链接: https://github.com/lusase/lineDrawer.git https://www.jb51.net/css/359062.html https://www.jb ...

  10. 高分一号计算NDVI

    1.准备工作 如果想要ENVI友好一点,请下载ENVI5.3,并且安装China satellites 补丁(参考博客:ENVI扩展工具:中国国产卫星支持工具) App Store for ENVI下 ...