博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Solidity的三种转账方式与比较
阅读量:4511 次
发布时间:2019-06-08

本文共 1238 字,大约阅读时间需要 4 分钟。

转账的3种方式

1 2 3
address.transfer() address.send() address.call.value().gas()()

转账transfer

1 2 3 4 5 6 7 8 9 10
function transfer(address _address) public payable{ _address.transfer(msg.value); } function transfer2(address _address) public payable{ _address.transfer(10 * 10**18); }

转账send

1 2 3
function transfer4(address _address) public payable { _address.send(10 ether); }

转账call

1 2 3
function transfer5(address _address) public payable returns(bool){ return _address.call.value(10 ether)(); }

对比总结

1 2 3 4 5 6
transfer与send相似,都为转账操作 transfer出错抛出异常 send、call出错不抛出异常,返回true或false tansfer相对send更安全 send、call即便转账失败也会执行其后的代码 慎用call函数转账,容易发生重入攻击。

  • 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

  • returns false on failure
  • 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

  • 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

转载于:https://www.cnblogs.com/x-poior/p/10511583.html

你可能感兴趣的文章
【Unity3D】获取鼠标在三维空间(世界坐标系)的位置
查看>>
Python虚拟机函数机制之名字空间(二)
查看>>
线段树
查看>>
SharePoint2010联合搜索——Google、百度
查看>>
php静态
查看>>
python基础之文件操作
查看>>
PAT B1033 旧键盘打字
查看>>
Fedora 8/9更新换源和更新中断解决方法
查看>>
[唐胡璐]Selenium技巧 - 定制元素属性检查,并写到ReportNG中
查看>>
hdu 1695 莫比乌斯基础题
查看>>
做题记录 To 2019.2.13
查看>>
Cg(C for Graphic)语言表达式与控制语句(转)
查看>>
C++中Static的作用
查看>>
一套完整的javascript面试题
查看>>
Centos7安装gitlab-ce
查看>>
centos7修改hostname
查看>>
正则表达式中的懒惰匹配与非捕获组
查看>>
Android 开发服务类 03_ServletForGETMethod
查看>>
一些基础名词及含义(更新中)
查看>>
sql索引优化 (从网上学习的时候总结的)
查看>>