Error: The network id specified in the truffle config (4) does not match the one returned by the network (1)

Viewed 629

I am trying to deploy to the Rinkeby testnet but the following error appears

Error: The network id specified in the truffle config (4) does not match the one returned by the network (1). Ensure that both the network and the provider is properly configured

I have tried to change the network id but the transaction doesn't go through returning another error that states that I have insufficient balance to perform the transaction while I have over 12 ETH for testing

1 Answers

This should be your truffle.config.networks

const HDWalletProvider = require("@truffle/hdwallet-provider");
// set the mnemonics from the rinkeby account
const { config } = require("./config");

networks: {
    development: {
      host: "127.0.0.1", // Localhost (default: none)
      port: 7545, // Standard Ethereum port (default: none)
      network_id: "*", // Any network (default: none)
    },
    rinkeby: {
      networkCheckTimeout: 10000,
      provider: () =>
        new HDWalletProvider({
          mnemonic: {
            phrase: config.metamask_mnemonic,
          },
          providerOrUrl: config.ropsten_network,
        }),

      network_id: 4, // rinkeby id
      // Instead of passing "from", you could pass third argument to the new HDWalletprovider as the index of account
      from: "0x3FB83280e44B4c1b88E8fb6ce6e0E1C271BB1659",
      gas: 4500000, // Ropsten has a lower block limit than mainnet
      confirmations: 2, // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 200, // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: true, // Skip dry run before migrations? (default: false for public nets )
    },
  },

  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      // default is 0.5.16
      version: "0.8.7", 
    },
  },

  // Truffle DB is currently disabled by default; to enable it, change enabled: false to enabled: true
  //
  // Note: if you migrated your contracts prior to enabling this field in your Truffle project and want
  // those previously migrated contracts available in the .db directory, you will need to run the following:
  // $ truffle migrate --reset --compile-all

  db: {
    enabled: false,
  },
};

HDWallet provider is used by truffle when we deploy the contract however metamask providers are used when we want to interact with the contract in the browser. Setting provider for contract interaction with metamask is different.

then make sure ganache is set correctly and running.

Related