92/666 fallback函数

作者: 红叔笔记 | 来源:发表于2018-12-04 22:35 被阅读0次

这是666计划的第91篇笔记

pragma solidity ^0.4.0;

contract Test {
    // This function is called for all messages sent to
    // this contract (there is no other function).
    // Sending Ether to this contract will cause an exception,
    // because the fallback function does not have the `payable`
    // modifier.
    function() public { x = 1; }
    uint x;
}


// This contract keeps all Ether sent to it with no way
// to get it back.
contract Sink {
    function() public payable { }
}

contract Caller {
    function callTest(Test test) public {
        test.call(0xabcdef01); // hash does not exist
        // results in test.x becoming == 1.

        // The following will not compile, but even
        // if someone sends ether to that contract,
        // the transaction will fail and reject the
        // Ether.
        //test.send(2 ether);
    }
}

在Metamask看到的效果如下“


image.png

相关文章

网友评论

    本文标题:92/666 fallback函数

    本文链接:https://www.haomeiwen.com/subject/oglbcqtx.html