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

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.

主站蜘蛛池模板: 高邮市| 九龙县| 绍兴市| 天水市| 讷河市| 崇明县| 明溪县| 如东县| 阜阳市| 新民市| 紫阳县| 福安市| 桂林市| 信宜市| 莲花县| 萨嘎县| 黄山市| 南投市| 封开县| 景宁| 新丰县| 孝昌县| 曲水县| 许昌市| 资中县| 大宁县| 阳朔县| 上高县| 永川市| 镇赉县| 乐安县| 蒙山县| 郁南县| 玉山县| 万载县| 雷波县| 灵武市| 任丘市| 英超| 岢岚县| 长阳|