2

I am having problems with truffle migrate on the default Truffle project and using Infura as the provider.

Steps to reproduce problem

  1. truffle init
  2. npm install ethereumjs-wallet bip39 web3-provider-engine@8.6.1 web3@0.18.4 zeppelin-solidity --save
  3. Edit truffle.js to use deterministic wallet and infura provider. (Code below)
  4. truffle compile
  5. truffle migrate --network rinkeby

However running truffle migrate --network rinkeby does only a partial migrate. It does not go on to migrate 2_deploy_contracts.js.

$ truffle migrate --network rinkeby
Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0xf7a1eea43cfe61d59f55a3f5ce8b1c33bc9d5b37c2486ebdc83fdf4d1ba03041
$ 

Anyone knows what might be the problem?


Using:

  • Truffle v3.4.9 (core: 3.4.8)
  • Solidity v0.4.15 (solc-js)

truffle.js

var bip39 = require("bip39");
var hdkey = require('ethereumjs-wallet/hdkey');
var ProviderEngine = require("web3-provider-engine");
var WalletSubprovider = require('web3-provider-engine/subproviders/wallet.js');
var Web3Subprovider = require("web3-provider-engine/subproviders/web3.js");
var Web3 = require("web3");

// Get our mnemonic and create an hdwallet
var mnemonic = "couch solve unique spirit wine fine occur rhythm foot feature glory away";
var hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic));

// Get the first account using the standard hd path.
var wallet_hdpath = "m/44'/60'/0'/0/";
var wallet = hdwallet.derivePath(wallet_hdpath + "0").getWallet();
var address = "0x" + wallet.getAddress().toString("hex");

var providerUrl = "https://rinkeby.infura.io/somekey";
var engine = new ProviderEngine();
engine.addProvider(new WalletSubprovider(wallet, {}));
engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(providerUrl)));
engine.start(); // Required by the provider engine.


module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    },

    rinkeby: {
        network_id: 4,
        provider: engine,
        from: address
    }
  }
};

Here's the output of truffle migrate --network rinkeby --verbose-rpc

Using network 'rinkeby'.

  Running migration: 1_initial_migration.js
     .> {
     .>   "jsonrpc": "2.0",
     .>   "id": 1,
     .>   "method": "eth_accounts",
     .>   "params": []
     .> }
   .<   {
   .<     "id": 1,
   .<     "jsonrpc": "2.0",
   .<     "result": [
   .<       "0xcede48d8ac162d1b08ed9419010de3c99f2cfdd6"
   .<     ]
   .<   }
     .> {
     .>   "jsonrpc": "2.0",
     .>   "id": 2,
     .>   "method": "net_version",
     .>   "params": []
     .> }
   .<   {
   .<     "id": 2,
   .<     "jsonrpc": "2.0",
   .<     "result": "4"
   .<   }
    Deploying Migrations...
     .> {
     .>   "jsonrpc": "2.0",
     .>   "id": 3,
     .>   "method": "net_version",
     .>   "params": []
     .> }
   .<   {
   .<     "id": 3,
   .<     "jsonrpc": "2.0",
   .<     "result": "4"
   .<   }
     .> {
     .>   "jsonrpc": "2.0",
     .>   "id": 4,
     .>   "method": "eth_sendTransaction",
     .>   "params": [
     .>     {
     .>       "from": "0xcede48d8ac162d1b08ed9419010de3c99f2cfdd6",
     .>       "gas": "0x47e7c4",
     .>       "gasPrice": "0x174876e800",
     .>       "data": "0x6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101e58061003c6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630900f010811461005e578063445df0ac1461007f5780638da5cb5b146100a4578063fdacd576146100d3575b600080fd5b341561006957600080fd5b61007d600160a060020a03600435166100eb565b005b341561008a57600080fd5b610092610182565b60405190815260200160405180910390f35b34156100af57600080fd5b6100b7610188565b604051600160a060020a03909116815260200160405180910390f35b34156100de57600080fd5b61007d600435610197565b005b6000805433600160a060020a039081169116141561017c5781905080600160a060020a031663fdacd5766001546040517c010000000000000000000000000000000000000000000000000000000063ffffffff84160281526004810191909152602401600060405180830381600087803b151561016757600080fd5b6102c65a03f1151561017857600080fd5b5050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a03908116911614156101b45760018190555b5b5b505600a165627a7a723058205f879dec75723925844d4fd706c85432c3686fa32c9ccf4e7a6ca2b8bb0307380029"
     .>     }
     .>   ]
     .> }
     .> {
     .>   "id": 1507552744042366,
     .>   "jsonrpc": "2.0",
     .>   "params": [
     .>     "0xcede48d8ac162d1b08ed9419010de3c99f2cfdd6",
     .>     "pending"
     .>   ],
     .>   "method": "eth_getTransactionCount"
     .> }
   .<   {
   .<     "id": 1507552744042366,
   .<     "jsonrpc": "2.0",
   .<     "result": "0x13"
   .<   }
     .> {
     .>   "id": 1507552744515044,
     .>   "jsonrpc": "2.0",
     .>   "params": [
     .>     "0xf902741385174876e8008347e7c48080b902216060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101e58061003c6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630900f010811461005e578063445df0ac1461007f5780638da5cb5b146100a4578063fdacd576146100d3575b600080fd5b341561006957600080fd5b61007d600160a060020a03600435166100eb565b005b341561008a57600080fd5b610092610182565b60405190815260200160405180910390f35b34156100af57600080fd5b6100b7610188565b604051600160a060020a03909116815260200160405180910390f35b34156100de57600080fd5b61007d600435610197565b005b6000805433600160a060020a039081169116141561017c5781905080600160a060020a031663fdacd5766001546040517c010000000000000000000000000000000000000000000000000000000063ffffffff84160281526004810191909152602401600060405180830381600087803b151561016757600080fd5b6102c65a03f1151561017857600080fd5b5050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a03908116911614156101b45760018190555b5b5b505600a165627a7a723058205f879dec75723925844d4fd706c85432c3686fa32c9ccf4e7a6ca2b8bb03073800291ba0b65823e784f3eccb6aee7f2832d6780df2d345052fc59b18a5fc0b695d5e59b3a06c6dccd25ca9f120883ba6ffec3a7a22bc38a06fa50e71159ee00e1990fbfc7f"
     .>   ],
     .>   "method": "eth_sendRawTransaction"
     .> }
   .<   {
   .<     "id": 1507552744515044,
   .<     "jsonrpc": "2.0",
   .<     "result": "0xf2b4e82e4a806ad1adcd8ff4e6d5cad05ee99302a2265810e3de04fd3a652c33"
   .<   }
   .<   {
   .<     "id": 4,
   .<     "jsonrpc": "2.0",
   .<     "result": "0xf2b4e82e4a806ad1adcd8ff4e6d5cad05ee99302a2265810e3de04fd3a652c33"
   .<   }
    ... 0xf2b4e82e4a806ad1adcd8ff4e6d5cad05ee99302a2265810e3de04fd3a652c33
     .> {
     .>   "jsonrpc": "2.0",
     .>   "id": 5,
     .>   "method": "eth_newBlockFilter",
     .>   "params": []
     .> }
  • What happens after this? Running migration: 1_initial_migration.js Deploying Migrations... ... 0xf7a1eea43cfe61d59f55a3f5ce8b1c33bc9d5b37c2486ebdc83fdf4d1ba03041 – pabloruiz55 Oct 9 '17 at 13:11
  • @pabloruiz55 I end up back in bash. It does not proceed to deploy 2_deploy_contracts.js – Nyxynyx Oct 9 '17 at 13:23
2

UPDATE: You can replace the code provided by the Infura / Truffle tutorial as follows, which is extremely shorter and easier to read/modify.

You can change all the code above for the two lines below to make it much easier.

var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "word1 word2 word3 etc";

Install truffle-hdwallet-provider package.

$ npm install truffle-hdwallet-provider

Then:

module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*' // Match any network id
    },
    ropsten: {
      provider: new HDWalletProvider(mnemonic, "https://ropsten.infura.io/wefbowufweufbweu"), // The actual api key infura gave you
      network_id: '3'
    }
  }
}

This example uses Ropsten, but changing it to Rinkeby should be trivial, just make sure you are using the url Infura gave you with the correct api key and network_id 4 instead of 3

  • What about 2_deploy_contracts.js? Truffle seems to quit after deploying 1_initial_migration.js – Nyxynyx Oct 9 '17 at 13:19
  • Try using the --reset flag to see if it makes a difference. What puzzles me is that the contract did get deployed as you can see on Etherscan. truffle compile --network rinkeby --reset truffle migrate --network rinkeby --reset – pabloruiz55 Oct 9 '17 at 13:24
  • Running with the --reset flag did not change anything... Are u on an older version of truffle for this to work? On testrpc, truffle proceeds to deploy 2_deploy_contracts.js – Nyxynyx Oct 9 '17 at 13:39
  • Just updated this answer. Hope it helps. @Nyxynyx – pabloruiz55 Oct 9 '17 at 13:53
  • It works when using truffle-hdwallet-provider!! Not sure why the previous code straight from Infura's website didnt work... – Nyxynyx Oct 9 '17 at 14:44

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.