I am using Truffle for writing smart contract. When I want to deploy to test network (i.e: rinkeby network), I use following command:

truffle migrate --network rinkeby

As this is log:

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0xc032b44fb7d51ad386b6c1e7d9910798e36e1590b9fd557d50348af090ce06e3
  Migrations: 0x44b273afa97a8c0c1dac41b2f5972b22c0a92bb2
Saving successful migration to network...
  ... 0x8fc27bea14c6c7e0bceac0c5232013211e8f7bd0cd05611935350b1fbf3c986b
Saving artifacts...
Running migration: 2_game_presale.js
  Deploying GamePresale...
  ... 0x154df08d0d55d51fc2d2f78a8ac643f94b9cfde2eb5081e6b31d12367a7994ee
  GamePresale: 0x3cd9498845833058e48fde58e521f34420123793
Saving successful migration to network...
  ... 0x789d608fd3302a931ef1ed744d50cfa63be24bde7d768c8508c0b978541e9b1f

Looks like that Truffle deploy to 2 contracts. So I go to etherscan for checking:

enter image description here

So based on this image, truffle has created 2 contracts. So my question is:

  • Why truffle creates 2 contract.
  • After every contract creation, truffle creates 1 more transaction. What is that ?


  • The first created contract is the Migrations contract. This is a contract generated by truffle init and is needed by Truffle to do migrations and remember migration steps.
  • After each migration step the Migrations contract is updated to store the step number in last_completed_migration. Each of your step contain only one contract creation but there could be more in each step.

    The second transaction stores 1 in last_completed_migration. The last transaction is executed after your second and last migration and store 2 in last_completed_migration.

  • So the first transaction is updates the migration state to "beginning" right ? – hqt May 28 '18 at 17:59
  • The first transaction creates Migrations. The second sets last_completed_migration to 1. The third creates GamePresale. The last updates last_completed_migration to 2. – Harold May 28 '18 at 18:04
  • thanks :D But why truffle needs to create this ? because I see, every time I run command deploy contract, truffle will creates new one from scratch. (i.e: create migration then create contract ...) – hqt May 28 '18 at 18:11
  • When the Migrations contract is already created, you can run the second migration only with the command truffle migrate -f 2. It will create GamePresale and update last_completed_migration in Migrations. It is more useful when you have more migrations steps: if a step fails it is not needed to redo all steps. – Harold May 28 '18 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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