0

truffle.js:

var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "";

module.exports = {
  networks: {
    testnet: {
      provider: () => new HDWalletProvider(mnemonic, ""),
      network_id: 97,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    },
    rinkeby: {
      host: '127.0.0.1',
      port: 8545,
      network_id: 4,
      gasPrice: "20000000000", // 20 gwei
    },
    live: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "1", // Only mainnet
      gasPrice: "10000000000", // 10 gwei
      gas: "5000000", // 0.02 eth at 4 gwei price
    },
  compilers: {
    solc: {
      version: "^0.8.4",
    },
  },
 }
};

But I keep getting the error: Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity >=0.8.4".

I have even tried the solutions in How to upgrade solidity compiler in truffle, but none helped.

How can I fix this?

1 Answer 1

1

There's a wrongly placed }. I suggest to format the file then it should be obvious that compiler is in the wrong section.

module.exports = {
  networks: {
    live: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "1", // Only mainnet
      gasPrice: "10000000000", // 10 gwei
      gas: "5000000", // 0.02 eth at 4 gwei price
    }, /////// <------ MISSING } //////
  compilers: {
    solc: {
      version: "^0.8.4",
    },
  },
 }     /////// <------ HERE IS THE MISSING } ///////
};

It should be like this

module.exports = {
  networks: {
    live: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "1", // Only mainnet
      gasPrice: "10000000000", // 10 gwei
      gas: "5000000", // 0.02 eth at 4 gwei price
    },
  },
  compilers: {
    solc: {
      version: "^0.8.4",
    },
  },
};
1
  • 1
    network and compilers should be sibling keys, so there needs to be another closing brace } above the compilers key to close out the network entry.
    – amal
    Jul 12, 2021 at 10:48

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.