zoukankan      html  css  js  c++  java
  • smart contract 知识点

    知识点

    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

  • 相关阅读:
    Linux修改主机名称方法
    高精度模板(含加减乘除四则运算)
    背包问题(0-1背包,完全背包,多重背包知识概念详解)
    [Swust OJ 385]--自动写诗
    [Swust OJ 403]--集合删数
    [Swust OJ 409]--小鼠迷宫问题(BFS+记忆化搜索)
    [Swust OJ 360]--加分二叉树(区间dp)
    [Swust OJ 402]--皇宫看守(树形dp)
    [Swust OJ 581]--彩色的石子(状压dp)
    [Swust OJ 589]--吃西瓜(三维矩阵压缩)
  • 原文地址:https://www.cnblogs.com/no7dw/p/9529776.html
Copyright © 2011-2022 走看看