- 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.
- 仿真模型可移植性規(guī)范及其應(yīng)用
- 概率論與數(shù)理統(tǒng)計
- 數(shù)學(xué)建模與數(shù)學(xué)規(guī)劃:方法、案例及編程實戰(zhàn)(Python+COPT/Gurobi實現(xiàn))
- 數(shù)學(xué)建模33講:數(shù)學(xué)與繽紛的世界
- The Modern C# Challenge
- 老師沒教的數(shù)學(xué)
- 幾何之美
- 特殊函數(shù)概論習(xí)題解答
- 燒腦的邏輯題
- 概率論與數(shù)理統(tǒng)計
- 線性代數(shù)
- 自然哲學(xué)的數(shù)學(xué)原理(漢譯世界學(xué)術(shù)名著叢書)
- 迷人的數(shù)學(xué)+美麗的數(shù)學(xué)(共2冊)
- 萊布尼茲微積分
- Radioss 基礎(chǔ)理論與工程高級應(yīng)用