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

  • Mastering Ethereum
  • Merunas Grincalaitis
  • 160字
  • 2021-06-24 15:01:07

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.

主站蜘蛛池模板: 登封市| 紫云| 瑞安市| 历史| 东山县| 岗巴县| 吉林市| 民丰县| 凌源市| 郁南县| 思南县| 甘孜| 巨鹿县| 墨脱县| 秦安县| 临西县| 峨山| 大埔区| 四子王旗| 永新县| 炉霍县| 灵川县| 通榆县| 白河县| 墨脱县| 如东县| 高陵县| 西华县| 平乐县| 乐陵市| 泰州市| 综艺| 上思县| 独山县| 河曲县| 平利县| 鹤峰县| 中宁县| 武城县| 永昌县| 盱眙县|