智能合约中我们可以根据不同的场景来使用这2中方式。下面来看看解释。
1. address.transfer()
- throws on failure // 转账失败会抛出异常
- forwards 2,300 gas stipend (not adjustable), safe against reentrancy
- should be used in most cases as it’s the safest way to send ether
2. address.send()
- returns false on failure // 转账失败会返回false
- forwards 2,300 gas stipend (not adjustable), safe against reentrancy
- should be used in rare cases when you want to handle failure in the contract
3. address.call.value().gas()()
- returns false on failure
- forwards all available gas (adjustable), not safe against reentrancy
- should be used when you need to control how much gas to forward when sending ether or to call a function of another contract
函数返回值就是transfer和send的最主要区别,生产中用transfer比较多。
Where there is a life, there is a hope.
书山有路勤为径,学海无涯苦作舟。
欢迎关注微信公众号:【程序员写书】
喜欢宠物的朋友可以关注:【电巴克宠物Pets】
一起学习,一起进步。
