目前来看,智能合约接受以太共有五种可能性;
xff0c; there are five possibilities for accepting an intelligent contract; xff1b;
一个合约最多有一个 函数, 声明函数为:
A contract has a maximum of one function, declaring it to be xff1a;
无需 关键字,也没有参数和返回值并且必须是可见性和 修饰。 它可以是 的,可以被重载也可以有修改器modifier 。
No keyword & #xff0c; there are no parameters and return values and must be visible and modifier. It can be & #xff0c; it can be reloaded or modified by a modifier.
在对合约没有任何附加数据调用(通常是对合约转账)是会执行 函数。
There is no additional data call for & #xff08 for contracts; usually for contractual transfers & #xff09; is a function to perform.
例如通过 or 如果 函数不存在,但是有payable的 fallback 回退函数 那么在进行纯以太转账时,fallback 函数会被调用。
For example, by or if the function does not exist xff0c; but there is Payable fallback , then the function xff0c; fallback is called when a purely too-too transfer is made.
如果两个函数都没有,这个合约就没法通过常规的转账交易接收以太,会抛出异常。
If neither function xff0c; the contract cannot receive Etherxff0c through a conventional transfer transaction; an anomaly occurs.
并且, 函数只有 2300 gas 可以使用, 除了基础的日志输出之外,进行其他操作的余地很小。下面的操作消耗会操作 2300 gas :
& xff0c; function only 2300 Gas can use xff0c; xff0c; there is little room for other operations, except for basic log output. The operation below consumes 2300 Gas:
- 写入存储
- 创建合约
- 调用消耗大量 gas 的外部函数
- 发送以太币
不过,与任何其他函数一样,只要有足够的 gas 传递给它,回退函数就可以执行复杂的操作。
, but , like any other functionxff0c; as long as has enough gas to pass to it, the regression function can perform complex operations.
合约可以最多有一个回退函数。函数声明为: 或
The contract may have a maximum of one regression function. The function is xff1a; or
没有关键字。必须是可见性,它可以是 的,可以被重载也可以有 修改器modifier 。
There are no keywords. It must be visible xff0c; it can be xff0c; it can be reloaded or it can be modified by a modifier.
fallback 函数始终会接收数据,但为了同时接收以太时,必须标记为 。
The fallback function always receives data & #xff0c; however, in order to receive & #xff0c at the same time, it must be marked as.
如果使用了带参数的版本, 将包含发送到合约的完整数据(等于 ),并且通过 返回数据。 返回数据不是 ABI 编码过的数据,相反,它返回不经过修改的数据。
If version xff0c with parameters is used; the complete data sent to the contract xff08; equals & #xff09; xff0c; and returns the data by return. Returning data is not xff0c; on the contrary xff0c; it returns unmodified data.
如果回退函数在接收以太时调用,只有 2300 gas 可以使用。
If the retraction function calls xff0c when receiving the Too; only 2300 gas is available.
不过,与任何其他函数一样,只要有足够的 gas 传递给它,回退函数就可以执行复杂的操作。
, but , like any other functionxff0c; as long as has enough gas to pass to it, the regression function can perform complex operations.
注:实现payable的fallback() 和receive() 的区别
- receive()优先接受纯以太的交易
- 实现payable的fallback()优先接受附带msg.data的交易
这种方式无需多言,加个payable关键词就可以了!
This approach does not require a lot of words xff0c; plus a Payable keyword xff01;
自毁函数是具有攻击性的一种让其它合约被迫接受以太的方式
Self-destruct is an offensive way of forcing other contracts to accept too much.
如上例所示,当调用合约的函数时,此合约将会自毁,并且将合约内的余额强制发送到 _ to这个合约地址上,无论_ to合约是否实现接受以太的函数,都不得不接受这笔转账。
xff0c; xff0c when calling the function of the contract; xff0c; the contract will self-destruct xff0c; and the balance in the contract will be sent to _to this contract address xff0c; regardless of whether to meet the acceptance of the function xff0c; and will have to accept the transfer .
我们常说的挖矿奖励,当挖出了一个新区块时,以太奖励将会达到挖出人指定的地址上,无论这个地址是什么,它都会多出这笔奖励余额;
What we often say is a mining incentive xff0c; xff0c when a new block is dug out; xyff0c will reach the address designated by the diggers xff0c; whatever the address is xff0c; it will add this reward balance xff1b;
如今以太坊转型为PoS权益证明机制,miner区块奖励将会逐渐销声匿迹。
Today, the Taiwan transition is a PoS equity certification mechanism #xff0c; the Miner block reward will gradually disappear.
注册有任何问题请添加 微信:MVIP619 拉你进入群

打开微信扫一扫
添加客服
进入交流群
发表评论