Solidity的一些学习心得,开发以太坊DAPP实战记录。
-> 前往星空笔记
Solidity实用笔记
5 years ago by lemooljiang (73)
$0.98
- Past Payouts $0.98
- - Author $0.56
- - Curators $0.42
37 votes
- + stevoperon: $0.416 (40%)
- + friendlystranger: $0.164 (16%)
- + lemooljiang: $0.157 (100%)
- + ace108: $0.074 (25%)
- + susanli3769: $0.049 (100%)
- + freepress: $0.025 (25%)
- + boosta: $0.014 (100%)
- + xiaoshancun: $0.013 (100%)
- + htliao: $0.012 (35%)
- + ew-and-patterns: $0.010 (4%)
- + smallpusher: $0.009 (31%)
- + tvb: $0.009 (50%)
- + sasaadrian: $0.008 (20%)
- + kimzwarch: $0.004 (8%)
- + yellowbird: $0.003 (100%)
- + dancingapple: $0.003 (50%)
- + davidke20: $0.001 (4%)
- + archisteem: $0.001 (7.5%)
- + coffeedrinker51: $0.001 (100%)
- + blc: $0.001 (100%)
- … and 17 more
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
ether wei finney szabo
1 ether = 1018 wei
1 ether = 1000 finney
1 ether = 1000000 szabo
1 Gwei = 109 wei
gas prise = 2 wei
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
在全局命名空间中已经存在了(预设了)一些特殊的变量和函数,他们主要用来提供关于区块链的信息或一些通用的工具函数。可以把这些变量和函数理解为Solidity语言层面的(原生)API 。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
public private external internal
可以访问,可以继承的是public external
只能内部访问,不可继承的是private internal
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
payable view pure
payable 可以接受以太币
view 只看不修改(状态变量)
pure 纯函数,不读也不写
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
memory storage
memory 存储在EVM内存中,主要有局部变量,函数参数
storage 存储在区块链中,主要有状态变量,复杂变量,数组
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
1 == 1 seconds
1 minutes == 60 seconds
1 hours == 60 minutes
1 days == 24 hours
1 weeks == 7 days
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
solidity v0.6.6
中文手册
官方手册
remix
remix手册
web3.js
web3中文手册
geth
汇智网
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
一经创建,每笔交易都收取一定数量的 gas ,目的是限制执行交易所需要的工作量和为交易支付手续费。EVM 执行交易时,gas 将按特定规则逐渐耗尽。
gas price 是交易发送者设置的一个值,发送者账户需要预付的手续费= gas_price * gas 。如果交易执行后还有剩余, gas 会原路返还。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
使用修饰器modifier可以轻松改变函数的行为。 例如,它们可以在执行函数之前自动检查某个条件。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
import * as symbolName from "filename";
import "filename" as symbolName;
然后所有全局符号都以
symbolName.symbol
格式提供。Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Assert, Require, Revert
assert 函数只能用于测试内部错误,并检查非变量。
require 函数用于确认条件有效性,例如输入变量,或合约状态变量是否满足条件,或验证外部合约调用返回的值。
revert 可以用来标记错误并回退当前的调用。 revert 调用中还可以包含有关错误信息的参数,这个信息会被返回给调用者。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
receive接收以太函数, 无名称,无参数,无返回值
一个合约最多有一个 receive 函数, 声明函数为:
receive() external payable {}
Fallback 回退函数,无名称,无参数,无返回值
合约可以最多有一个回退函数。函数声明为:
fallback () external [payable] {}
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
合约代码从区块链上移除的唯一方式是合约在合约地址上的执行自毁操作 selfdestruct 。合约账户上剩余的以太币会发送给指定的目标,然后其存储和代码从状态中被移除。移除一个合约听上去不错,但其实有潜在的危险,如果有人发送以太币到移除的合约,这些以太币将永远丢失。
尽管一个合约的代码中没有显式地调用 selfdestruct ,它仍然有可能通过 delegatecall 或 callcode 执行自毁操作。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
参考
OpenZeppelin
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit