1

I have a bit weird situation..I was able to deploy my contract to local Ganache instance with:

truffle migrate --network develop

However, now when I make any change to the contract and run the same command, my contract gets compiled but at the end I get

Network up to date

Now I'm not sure why this is happening ? The contract is not the same, although I have changed just a few lines of code and parameters and the return values are the same, could that be the reason ?

Also, I thought it would work with:

truffle deploy --reset

However I get this:

Compiling your contracts...
===========================
Everything is up to date, there is nothing to compile.

Something went wrong while attempting to connect to the network. Check your network configuration.

Could not connect to your Ethereum client with the following parameters:
    - host       > 127.0.0.1
    - port       > 7545
    - network_id > 5777

Now its weird that is trying to use port 7545 when I run command with a --reset option...as my truffle-config points to port 8545:

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  contracts_build_directory: path.join(__dirname, "client/src/contracts"),
  networks: {
    develop: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*",
    }
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.4",    // Fetch exact version from solc-bin (default: truffle's version)
     }
    }
  },
};

I did previously have Ganuche running on 7545 as an experiment, but it hasn't been running on that port for a while, and

truffle migrate --network develop

was able to connect and execute initial migration. It's just that now it won't pick any new changes. Any ideas what is going on ?

Zed
  • 5,683
  • 11
  • 49
  • 81

2 Answers2

3

No, truffle will migrate only no-executed migrations as documentation said: Running migrations - Command

If your migrations were previously run successfully, truffle migrate will start execution from the last migration that was run, running only newly created migrations. If no new migrations exists, truffle migrate won't perform any action at all. You can use the --reset option to run all your migrations from the beginning.

So, if you already migrated a contract, you should execute:

truffle migrate --reset
georgeos
  • 2,351
  • 2
  • 24
  • 28
2

1- Migrating updated contract:

First of all, you should not expect to see a newer version of your contract with the same address. Updating a contract means creating a new contract. See here. Therefore you should treat your updated contract as a new contract and add a new migration scrip by incrementing the last script number. E.g,. if the last one is 2_my_contract, the new one should be 3_my_updated_contract. As @georgos pointed out, truffle will only make a new migration if there is a new migration script. The last migrated script number is actually kept in blockchain by the first migratin contract comes with the truffle Migrations.sol => 1_initial_migration.js.

2- Network:

If you don't provide the name of a defined network, truffle will use the default one. And, the default network's name is development. So, if you want to override the default behavior, change the network name from develop to development. Or, simply pass the network name in commands truffle migrate --network my_network

T.belli
  • 21
  • 2