I'm learning solidity with the book "Master etherum". I'm trying to use following program in truffle.


// 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 {

    // 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

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) {

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.

1 Answer 1


Neverminds guys, I found my 1_initial_migrations file was .sol and I change it into .js. Then it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.