知识点

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. MyLog

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;us ...

  2. Python基础-Python的三元运算符和lambda表达式

    1. Python的三元表达式: 现在大部分高级语言都支持 “?”这个三元运算符,它对应的表达式如下:condition ? value if true:value if else 但是 Python ...

  3. 在当前TestSuite/TestCase run之前先run另一个TestSuite/TestCase

    在当前的TestSuite/TestCase的Setup Script里面写上这段代码: import com.eviware.soapui.model.support.PropertiesMap l ...

  4. MySQL行转列、列转行

    一.行转列 有如图所示的表,现在希望查询的结果将行转成列 建表语句如下: CREATE TABLE `TEST_TB_GRADE` ( `ID` int(10) NOT NULL AUTO_INCRE ...

  5. webpack学习笔记 ——篇2

    插件整理 extract-text-webpack-plugin 用于将css/less/sass等文件单独打包 https://webpack.docschina.org/plugins/extra ...

  6. 马凯军201771010116《面向对象与程序设计Java》第九周学习总结

    一.理论知识部分 异常.日志.断言和调试 1.异常:在程序的执行过程中所发生的异常事件,它中断指令的正常执行. 2.Java的异常处理机制可以控制程序从错误产生的位置转移到能够进行错误处理的位置. 3 ...

  7. https加密流程

     引用其它博主博客,在这里谢谢这位博主,原博客地址:https://blog.csdn.net/xincai/article/details/51954468 1,下面,用一幅图展示一下https建立 ...

  8. kaptcha生成java验证码

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

  9. Mac OSX 编译 LeanSDR

    LeanSDR:Lightweight, portable software-defined radio git clone http://github.com/pabr/leansdr.git cd ...

  10. OpenStack源码分析 Neutron源码分析(一)-----------Restful API篇

    原文:https://blog.csdn.net/happyanger6/article/details/54586463 首先,先分析WSGI应用的实现. 由前面的文章http://blog.csd ...