知识点

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. js 原型原型链

    个人的理解,有什么不正确的请指教,共同学习 //声明一个构造函数Personfunction Person(name,age){ this.name = name; this.age = age;} ...

  2. Excel--------实用功能(数据对比)

    --excel数据在sql中查询展示出来 SELECT * FROM (SELECT '101001' as code ,'上海宝山站' as name union allSELECT '102083 ...

  3. 微信小程序 画布drawImage实现图片截取

    大多数图片都大小不一,选择框的尺寸也是宽高相等的,就会有图片被压缩 解决方法: 1.可以使用画布对图片先进行截取,保存截取图片(用户自己选取,或者指定图片中心区域截取),但是对于多张图片手动截取,会影 ...

  4. k-means缺陷

    k均值算法非常简单且使用广泛,但是存在的缺陷有: 1. K值需要预先给定: 属于预先知识,很多情况下K值的估计非常困难. 2. K-Means算法对初始选取的聚类中心点是敏感的: 不同的随机种子点得到 ...

  5. 伪Ajax-iframe

    由于HTML标签的iframe标签具有局部加载内容的特性,所以可以使用其来伪造Ajax请求. <!DOCTYPE html> <html lang="en"> ...

  6. python+appium 自动化2--元素定位uiautomatorviewer

    出处:https://www.cnblogs.com/yoyoketang/p/6128741.html 前言: 可以打开手机上的app了,下一步元素定位uiautomatorviewer,通过定位到 ...

  7. vue将网页中的特定部分转成pdf并下载(仅供个人学习记录)

    先安装支持 将页面html转换成图片npm install --save html2canvas 将图片生成pdfnpm install jspdf --save 组件引用: import html2 ...

  8. 2018-2019-2 《网络对抗技术》Exp6 信息搜集与漏洞扫描 20165326

    信息搜集与漏洞扫描 实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 基础知识 间接:不接触目标,无直接连接访问,使用辅助模块进行收集分析 DNS:执行各种相关查询 搜索引擎 直接:建立逻辑连 ...

  9. TCP端口检测工具

    很多时候,我们需要测试 tcp 端口.ping 命令虽然好用,但不能测试端口,因为 ping 基于ICMP协议,属于IP层协议,所以无法测试传输层的 TCP/UDP 端口.幸好有tcping命令,可以 ...

  10. input.nextLine()的注意事项

    若在input.nextInt()和input.nextDouble()后使用input.nextLine(),要先加一个input.nextLine()进行换行