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

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.

主站蜘蛛池模板: 陈巴尔虎旗| 伊川县| 库车县| 武乡县| 香格里拉县| 临颍县| 甘泉县| 九龙城区| 太谷县| 郧西县| 普陀区| 红安县| 南华县| 务川| 搜索| 沁源县| 和林格尔县| 军事| 故城县| 太和县| 云霄县| 连江县| 东至县| 安徽省| 武义县| 南平市| 大港区| 伊金霍洛旗| 隆化县| 府谷县| 泸溪县| 象山县| 建水县| 平阳县| 余庆县| 云林县| 江安县| 周宁县| 桃园市| 勐海县| 武乡县|