乐知付加密服务平台

如果你有资源, 平台可以帮你实现内容变现, 无需搭建知识付费服务平台。

点击访问官方网站 https://lezhifu.cc

扫码关注公众号 乐知付加密服务平台-微信公众号
Solidity中transfer和send的区别 | chenzuoli's blog

Solidity中transfer和send的区别

      智能合约中我们可以根据不同的场景来使用这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】
电巴克宠物

一起学习,一起进步。

-------------本文结束感谢您的阅读-------------