solidity基础-Receive

test

pragma solidity >=0.7.0 <0.9.0;
contract ReceiveTest {

    string public data;

    receive() external payable{
        data = "receive call";
    }

    fallback() external payable{       
        data = "fallback call";
    }

    function getBalance() public view returns(uint){
        return address(this).balance;
    }
    
}

ganache

 

metamask 设置网络

  

设置部署选项为 Injected Web3

    

 

部署

 

posted @ 2022-06-08 09:55  apeNote  阅读(26)  评论(0编辑  收藏  举报