Solidity 没名字的function(){...}作用
官方解释:
这个叫做fallback function,当有人 1. 只发送以太币给合约而不带任何输入数据;2. 调用smart contract时调起了一个不存在的方法。会触发执行这个方法。
What is the deal with “function () { ... }” inside Solidity contracts? How can a function not have a name?
This function is called “fallback function” and it is called when someone just sent Ether to the contract without providing any data or if someone messed up the types so that they tried to call a function that does not exist.
The default behaviour (if no fallback function is explicitly given) in these situations is to just accept the call and do nothing. This is desireable in many cases, but should only be used if there is a way to pull out Ether from a contract.
If the contract is not meant to receive Ether with simple transfers, you should implement the fallback function as
function() { throw; }
this will cause all transactions to this contract that do not call an existing function to be reverted, so that all Ether is sent back.
Another use of the fallback function is to e.g. register that your contract received ether by using an event.
Attention: If you implement the fallback function take care that it uses as little gas as possible, because send() will only supply a limited amount.
如果不定义这个方法,所有被误转到这个合约上的以太币将被拒绝。
Solidity 没名字的function(){...}作用的更多相关文章
- 【JS】 +function(){} 作用
原文地址:https://www.jianshu.com/p/a2666014a280 瞎扯 在JS中,经常会遇到下面这种 代码, 到底 在 function 前面加一个 一元操作符, 有什么作用呢? ...
- JavaScript原型链以及Object,Function之间的关系
JavaScript里任何东西都是对象,任何一个对象内部都有另一个对象叫__proto__,即原型,它可以包含任何东西让对象继承.当然__proto__本身也是一个对象,它自己也有自己的__proto ...
- java代码之美(15)---Java8 Function、Consumer、Supplier
Java8 Function.Consumer.Supplier 有关JDK8新特性之前写了三篇博客: 1.java代码之美(1)---Java8 Lambda 2.java代码之美(2)---Jav ...
- java代码(15) ---java8 Function 、Consumer 、Supplier
Java8 Function.Consumer.Supplier 有关JDK8新特性之前还有三篇博客: 1,java代码(1)---Java8 Lambda 2,java代码(2)---Java8 S ...
- c++11 function bind 测试。
实验小结 1)function 是一个模板类.有函数指针成员.可以看作安全型函数指针. template<typename _Res, typename... _ArgTypes> cla ...
- JavaScript中的Function类型浅析
1. Function类型是js中引用类型之一,每个函数实际上都是Function类型的实例对象,具有自己的属性和方法.正因为函数式对象,所以函数名实际上也是一个指向函数对象的指针. 2. 常用的函数 ...
- Python3 与 C# 基础语法对比(Function专栏)
Code:https://github.com/lotapp/BaseCode 多图旧版:https://www.cnblogs.com/dunitian/p/9186561.html 在线编程: ...
- C++ 名字空间namespace的使用
A namespace is a scope.C++ provides namespaces to prevent name conflicts.A namespace is a mechanism ...
- 【转载】resolv.conf中search作用
原文地址:http://www.oliver.ren/linux/387.html reslov.conf中的search主要是用来补全hostname的,有时候域名太长,可以做一个短域名做主机名字, ...
随机推荐
- Windows 7 扩展玻璃效果(Aero Glass)
转自:http://www.cnblogs.com/gnielee/archive/2010/10/04/windows7-extend-aero-glass.html Windows 7 操作系统默 ...
- VUE API 重点
VUE API 重点 生命周期方法 每个组件都有生命周期,是向 ReactJs 学习的. computed 在一个组件声明一个人,人有名,人有姓,输入姓和名.((&--&%--& ...
- NOIp2018 D2T3 defense——树上倍增
题目:https://www.luogu.org/problemnew/show/P5024 考场上只会写n,m<=2000的暴力,还想了想A1和A2的情况,不过好像只得了A1的分.然后仔细一看 ...
- Tomcat服务器下 catalina.out 日志开关
很多异常在 debug 日志里不会打印,但在 catalina.out 里会打印,比如方法调用找不到,jdk 版本不匹配等.但是打开了该日志开关又会产生一个问题,就是它会哗啦啦的不断急剧膨胀,文件太大 ...
- 【Http认证方式】——Basic认证
访问请求:http://192.168.2.113:8080/geoserver/rest/workspaces时,浏览器弹出窗口需要输入用户名和密码 ,并且,如果不输入或者输入错误,浏览器返回 ...
- erlang 应用获取系统参数
很多时候,我们的程序需要一些预定义的参数,比如上次说的tcp_server的例子 一般参数有几种途径,具体参考这里http://blog.yufeng.info/archives/2852 app里面 ...
- java工具类mht转html格式文件 及简单的HTML解析
package com.szy.project.utils; import java.io.BufferedInputStream; import java.io.BufferedOutputStre ...
- 何时会发生db file sequential read等待事件?
很多网友对系统内频繁发生的db file sequential read等待事件存有疑问,那么到底在那些场景中会触发该单块读等待事件呢? 在我之前写的一篇博文<SQL调优:Clustering ...
- js中的webworker
js中的webworker webworker的作用类似于java的多线程 以独立文件的形式运行webworker index.html <!DOCTYPE html> <html ...
- Maven的安装及配置、Maven在Eclipse中的配置
一.需要准备的东西 1. JDK 2. Eclipse 3. Maven程序包 二.检查JAVA安装 三.安装Maven 下载apache-maven-3.5.3-bin.zip解压即可. 四.配置M ...