0

I have been trying to deploy my contract to Rinkbey, but nothing seems happening.

I have earlier deployed contracts locally to ganache RPC and used truffle migrate it worked fine and I was able to call deployed contract's method without any problem.

After that, I added following lines into truffle.js

rinkeby: {
  host: "127.0.0.1", // Connect to geth on the specified
  port: 8545,
  from: "xxxxxxxxxxxxxxxx", // find it from geth console by typing `eth.accounts` use the first one
  network_id: 4,
  gas: 5000000 
}

so it became

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*"
    },
    rinkeby: {
      host: "127.0.0.1", // Connect to geth on the specified
      port: 8545,
      from: "xxxxxxxxxxxx", // find it from geth console by typing `eth.accounts` use the first one
      network_id: 4,
      gas: 5000000 // Gas limit
    }
  }
};

My migrations/1_initial_migration.js is as follows:

var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

and contracts/Migrations.sol is as follows:

pragma solidity ^0.4.17;

contract Migrations {
  address public owner;
  uint public last_completed_migration;

  modifier restricted() {
    if (msg.sender == owner) _;
  }

  function Migrations() public {
    owner = msg.sender;
  }

  function setCompleted(uint completed) public restricted {
    last_completed_migration = completed;
  }

  function upgrade(address new_address) public restricted {
    Migrations upgraded = Migrations(new_address);
    upgraded.setCompleted(last_completed_migration);
  }
}

after that, I stopped local running geth and ran following command to unlock the account to get ready for deploying contract to rinkbey

geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --unlock="xxxxxxxxxxxxxxxx"

then ran following command in different terminal window

truffle compile; truffle migrate --network rinkeby

and got this output

Using network 'rinkeby'.

Network up to date.

While I was expecting it should have shown me completed migration to rinkbey and contract address, but it just keep saying Network is up to date. Even I edited my contract a bit thinking, that may fire new migration. But that did not help. Any idea what am I doing wrong here?

UPDATE: I read somewhere, I need to delete the build folder, so I did it. Then ran truffle compile; truffle migrate --network rinkeby and got followings this time:

Compiling ./contracts/Migrations.sol...
Compiling ./contracts/addition.sol...
Writing artifacts to ./build/contracts

Using network 'rinkeby'.

Network up to date.

Still I don't see deployed contract address?

  • Do you have deployer.deploy(addition) in a migration anywhere? It looks like you only have the Migration contract listed. You should have another deploy file called 2_deploy.js (it can be called anything as long as it starts with 2_). The contents should be nearly the same as 1_initial_migration.js, but describes how to deploy your contract (constructor arguments, dependencies, etc). – Adam Kipnis Mar 19 '18 at 2:26
  • @AdamKipnis I can see only one file under my migrations folder and that is 1_initial_migration.js and I have posted that file content above in my description. That is the ONLY file which has deployer.deploy(addition) My other contract name is addition.sol so I think you are saying I should also see 2_addition.js file under migrations folder? but I don't see any such file there. – JVK Mar 19 '18 at 2:32
1

make a new file called 2_deploy_contracts.js which will be automatically called after initial migration

1_initial_migration.js will only update the already deployed migrations contract

var myContract = artifacts.require("MyContract");

module.exports = function(deployer) {
  deployer.deploy(myContract);
};
  • Thank Nico. But can you educate me why should I create this second file. It should have auto generated by truflle when I run truffle compile; truffle migrate --network rinkeby ? isn't it? I think you have a typo ..first line of the migration artifact path should be artifacts.require("./MyContract"); – JVK Mar 19 '18 at 2:47
  • 1
    Truffle will look in the contracts folder by default actually. This require statement is not to be confused with node's require statement. Maybe not such a clear naming convention on truffle's part. afaik this file is not auto-generated because this is where you would also specifiy constructor parameters and truffle can not auto-generate those. eg. deployer.deploy(myContract, param1, param2, ... , options) Quote from the docs: "From here, you can create new migrations with increasing numbered prefixes to deploy other contracts and perform further deployment steps." – Nico Mar 19 '18 at 2:55
  • Got it.. thanks @nico. Accepting your answer. You should still correct the path artifacts.require("MyContract"); to artifacts.require("./MyContract"); – JVK Mar 19 '18 at 3:03

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.