基于Remix编译器0.8.1版本实现Ether Faucet功能
因为教程版本太老(0.4.9),导致频繁报错 把坑写一下
1. 报错:
TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address". -->
解决方案:
Function里定义address时写为:
function transfer(address payable _to, uint256 _value) public {...}
定义为address _to则会报错。编译器0.5.0更新所致,区分了address和address payable的类型。
2. 报错:
ParserError: Expected a state variable declaration. If you intended this as a fallback function or a function to handle plain ether transactions, use the "fallback" keyword or the "receive" keyword instead.
教程里的回跳函数为
function () payable public{} 运行时报错:
解决方案:依然是版本更新问题,现在的回跳函数写作fallback(),在一个合约中最多有一个fallback()函数,函数声明为:
fallback () payable external {...}