How to send Ether?
You can send Ether to other contracts by
- transfer (2300 gas, throws error)
- send (2300 gas, returns bool)
- call (forward all gas or set gas, returns bool)
How to receive Ether?
A contract receiving Ether must have at least one of the functions below
- receive() external payable
- fallback() external payable
- receive() is called if msg.data is empty, otherwise fallback() is called.
以下为示例合约:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
contract ReceiveEther {
/*
Which function is called, fallback() or receive()?
send Ether
|
本文介绍了如何在以太坊智能合约中发送Ether,包括使用transfer、send和call方法,并且详细说明了接收Ether时,合约应包含receive()或fallback()外部可支付函数的必要性。
订阅专栏 解锁全文
1624

被折叠的 条评论
为什么被折叠?



