知识点

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. vue双向数据绑定

    本文来源于 https://jingyan.baidu.com/article/91f5db1b0c2a4f1c7f05e3a8.html

  2. TP自动提取关键词

    protected function _before_insert(&$data, $option) {        $data['create_time'] = time();       ...

  3. Python列表的增删改查和元祖

    一.定义列表 1.names = ['mike','mark','candice','laular'] #定义列表 2.num_list = list(range(1,10)) #range生成1-1 ...

  4. 集合练习 练习:每一个学生Student都有一个对应的归属地定义为String类型。学生属性:姓名,年龄 注意:姓名和年龄相同的视为同一个学生。保证学生的唯一性。 1、描述学生。 2、定义Map容器,将学生作为键,地址作为值存入集合中。 3、获取Map中的元素并进行排序。

    package com.rf.xs.map; public class Student implements Comparable<Student> { private String na ...

  5. MAC安装flutter开发环境

    #最近在学flutter开发,写一篇记录一下安装的过程 1.配置flutter镜像地址  vim ~/.bash_profile 命令行输入后回车,打开.bash_profile配置镜像地址 expo ...

  6. nginx 多域名指向多个根目录配置,设置自定义请求头 proxy_set_header,ssl 证书安装配置

    1.nginx.conf 配置文件引入子配置文件 include vhost-server/*.conf;  关键在 server_name  不同域名执行不同的根 user root; #user ...

  7. Charles篡改请求,在手机上抓包,以及弱网设置

    篡改请求 可以测试各种异常 原理:clint->server正常是客户端发送请求到服务端,charles相当于一个拦截器,拦住客户端的请求,并进行修改,修改后再发送到server端 Server ...

  8. 棋盘(noip2017普及组)

    题目描述 有一个m \times mm×m的棋盘,棋盘上每一个格子可能是红色.黄色或没有任何颜色的.你现在要从棋盘的最左上角走到棋盘的最右下角. 任何一个时刻,你所站在的位置必须是有颜色的(不能是无色 ...

  9. dede织梦系统接入熊掌号推送api,完整详细教程

    第一步:     根据熊掌号要求完成校验页面,官方文档很详细,照着弄就行了 第二步: 开始后台改造 1.进入后台文件夹dede(自己实际的文件夹),然后进入templets目录,打开body_inde ...

  10. RabbitMQ集群出现过机器故障,网络异常等故障后,重启无法重新建立集群的终极解决方案

    由于机器掉电,网络故障等原因,RabbitMQ整个集群出现问题.重启RabbitMQ时,发现某些机器始终无法重新加入到集群中,而且还可能出现网络分区. 针对不同情况,可能选择 rabbitmqctl ...