官术网_书友最值得收藏!

The fallback function

This is a special type of function that doesn't have a name. It is executed whenever someone uses the .send() or .transfer() function to this contract address, similar to a default function. It is often used in ICOs to receive Ether and return the specified number of tokens for the Ether received. This allows anybody to buy tokens without having to understand and deploy the contract instance, with just the address of the contract.

Here's how it looks:

function () external payable {}

Fallback functions must be marked external to help people understand that it shouldn't be executed inside this contract by mistake. If you don't add the payable modifier, it will reject all the transactions sending it Ether.

I recommend that you should write and try different functions using the remix.ethereum.org IDE, which will show you errors and notifications about things that must be verified. That way, you'll be able to write your own contract securely.

主站蜘蛛池模板: 十堰市| 逊克县| 竹溪县| 平乐县| 额济纳旗| 黄龙县| 海宁市| 墨江| 高要市| 嫩江县| 遂平县| 静宁县| 临邑县| 陇西县| 泽州县| 富源县| 彭泽县| 葵青区| 南安市| 五华县| 凤凰县| 会理县| 格尔木市| 铁岭县| 上饶市| 西充县| 罗甸县| 红原县| 前郭尔| 策勒县| 米易县| 弥渡县| 蒙山县| 蒙阴县| 清徐县| 宁国市| 保康县| 二连浩特市| 紫金县| 福安市| 湖口县|