function get_balance() public view returns(uint){ return this.balance; } }
contract TestMain{
constructor() payable{}
functiontransfer(address a) public returns (bool){ a.transfer(1 ether); return true; } }
再次调用 Main 合约的 transfer 就会出现错误,转账失败。
1 2 3 4 5 6
transact to TestMain.transfer errored: VM error: revert.
revert The transaction has been reverted to the initial state. Note: The calledfunction should be payable if you send valueand the value you send should be less than your current balance. Debug the transactiontoget more information.
如果,把 Main 函数中的 a.trnasfer 换成 a.send ,会发现,上面执行成功,但是,实际上是没有成功的,因为,send 不会返回异常,而是会返回 false。