3

I'm trying to use the Infura or any other public provider to compile and migrate a simple test contract.

I don't get any errors when I run

truffle compile --network test

but it seems to hang and never complete

same with

truffle migrate --network live

here is a copy of my truffle.js (the mnemonic is made up in the below)

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 FiltersSubprovider = require('web3-provider-engine/subproviders/filters.js');
var Web3Subprovider = require("web3-provider-engine/subproviders/web3.js");
var Web3 = require("web3");
var mnemonic = "know give beef link depth liberty fish forward ketchup fog either faculty";
var hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic));
var wallet_hdpath = "m/44'/60'/0'/0/";
var wallet = hdwallet.derivePath(wallet_hdpath + "0").getWallet();
var address = "0x" + wallet.getAddress().toString("hex");
var provider_url = "https://testnet.infura.io/";
var engine = new ProviderEngine();
engine.addProvider(new WalletSubprovider(wallet, {}));
engine.addProvider(new FiltersSubprovider());
engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(provider_url)));
engine.start(); 

module.exports = {
  networks: {
    test: {
      network_id: 3,
      provider: engine,
      from: address
    }
  }
};

And my package.json is

    {
  "name": "Infura Test",
  "version": "1.0.0",
  "description": "",
  "main": "truffle.js",
  "directories": {
    "test": "test"
  },
  "devDependencies": {
    "bip39": "^2.3.1",
    "ethereumjs-wallet": "^0.6.0",
    "truffle": "^3.4.5",
    "web3": "^0.18.2",
    "web3-provider-engine": "^13.2.8"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "@bkawk",
  "license": "ISC"
}
3

This answer shows how to use the package truffle-hdwallet-provider and Infura:

In truffle.js:

var HDWalletProvider = require("truffle-hdwallet-provider");

var infura_apikey = "XXXXXX";
var mnemonic = "twelve words you can find in metamask/settings/reveal seed words blabla";

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    },
    ropsten: {
      provider: new HDWalletProvider(mnemonic, "https://ropsten.infura.io/"+infura_apikey),
      network_id: 3
    }
  }
};

Deploy on the ropsten network

$ truffle migrate --network ropsten
1

Try adding this:

// network connectivity error
engine.on('error', function(err) {
    // report connectivity errors
    console.error(err.stack)
})

before engine.start();

0

var provider_url = "https://testnet.infura.io/";

Try putting in your personal URL (that one with the key), e.g. "https://ropsten.infura.io/YourKeyThatWasSentToYourEmail"

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.