I'm learning solidity with the book "Master etherum". I'm trying to use following program in truffle.
https://github.com/ethereumbook/ethereumbook/blob/develop/code/Solidity/Faucet4.sol
// SPDX-License-Identifier: CC-BY-SA-4.0
// Version of Solidity compiler this program was written for
pragma solidity ^0.6.4;
// Our first contract is a faucet!
contract Faucet {
address payable owner;
// Contract constructor: set owner
constructor() public {
owner = msg.sender;
}
// Access control modifier
modifier onlyOwner {
require(msg.sender == owner);
_;
}
// Accept any incoming amount
receive() external payable {}
// Contract destructor
function destroy() public onlyOwner {
selfdestruct(owner);
}
// Give out ether to anyone who asks
function withdraw(uint withdraw_amount) public {
// Limit withdrawal amount
require(withdraw_amount <= 0.1 ether);
// Send the amount to the address that requested it
msg.sender.transfer(withdraw_amount);
}
}
Since now truffle init won't create migration file under migration folder, I've tried code like this for initial migration
var Migrations = artifacts.require("./Migrations.sol");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};
But I keep getting error "Expected pragma, import directive or contract/interface/library/struct/enum definition.", even it compiled successfully in truffle.
I've tried add "pragma solidity ^0.6.4" on top of the file but it didn't work.