第123篇 笔记-sendEther合约
Posted wonderBlock
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第123篇 笔记-sendEther合约相关的知识,希望对你有一定的参考价值。
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
|
msg.data is empty?
/ \\
yes no
/ \\
receive() exists? fallback()
/ \\
yes no
/ \\
以上是关于第123篇 笔记-sendEther合约的主要内容,如果未能解决你的问题,请参考以下文章