0

I am trying to deploy a contract to Ropsten using Infura with the config file truffle.js below. The deploy fails because the account listed in the error message has insufficient funds – however I do not recognise the account given. It does not appear in the top 15 accounts associated with my mnemonic (e.g. using MyEtherWallet). I am inserting my mnemonic in the format word word word word.

The actual account 0 associated with my mnemonic has ample Ether from the faucet.

What am I doing wrong?

truffle.js

var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "<MNEMONIC>";
var infuraAPIKey = "<INFURA-PROJECT-SECRET>";
const infuraUrl = 'https://mainnet.infura.io/'+infuraAPIKey;

const NonceSubprovider = require("web3-provider-engine/subproviders/nonce-tracker"); 
const createInfuraProvider = (mnemonic, infuraUrl) => { 
  let provider = new HDWalletProvider(mnemonic, infuraUrl); 
  provider.engine.addProvider(new NonceSubprovider()); 
  return provider; 
}
module.exports = {
   networks: {
     development: {
       host: "localhost",
       port: 7545,
       network_id: "*" // Match any network id
    },
    rinkeby: {
      host: "localhost",
      provider: () => new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/"+infuraAPIKey, 0),
      port: 7545,
      network_id: 4,
      gas: 4712388
    },
    live: {
      host: "localhost",
      port: 8546,
      provider: createInfuraProvider(mnemonic, infuraUrl),
        network_id: 1,
        gas: 4712388
    }
  },
  compilers: {
    solc: {
      version: "0.4.24"
    }
  }
}; 

Error message:

1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
Error:  *** Deployment Failed ***

"Migrations" could not deploy due to insufficient funds
   * Account:  0xdBB63dca232c0deF386758eAC53A0B7Cc558217b
   * Balance:  0 wei
   * Message:  sender doesn't have enough funds to send tx. The upfront cost is: 9424776000000000 and the sender's account only has: 0
   * Try:
      + Using an adequately funded account
      + If you are using a local Geth node, verify that your node is synced.

    at /Users/technical/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/packages/truffle-deployer/src/deployment.js:364:1
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.7 (core: 5.0.7)
Node v10.15.3
0

HDWalletProvider and MyEtherWallet, They both are work differently so there is some alternative you can use:

  1. Using Private keys:
var HDWalletProvider = require("truffle-hdwallet-provider");
//load single private key as string
var provider = new HDWalletProvider("3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580", "http://localhost:8545");

// Or, pass an array of private keys, and optionally use a certain subset of addresses
var privateKeys = [
  "3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580",
  "9549f39decea7b7504e15572b2c6a72766df0281cea22bd1a3bc87166b1ca290",
];
var provider = new HDWalletProvider(privateKeys, "http://localhost:8545", 0, 2); //start at address_index 0 and load both addresses
  1. Update Migration File to Get Addresses:
module.exports = function(deployer,network,accounts) {   
console.log(accounts);  
deployer.deploy(Migrations); 
};
  • This still does not work. I changed your line console.log(a) to console.log(accounts) and it shows a different list of accounts each time. However, the Account listed by Truffle as the deploying account with no funds remains the same, and is unrelated to the private key. I am using MetaMask to extract the private key. Any other ideas? – user77510 Mar 11 at 8:46
  • Either When you go for **console.log(accounts)** it will show all addresses that are generated so next time you know what address will be responsible for transaction and so you can fill that account with some ether. Or Instead of using **mnemonic** you can use private that can be extract from Metamask – Kamal Kishor Mehra Mar 12 at 8:53
  • The trouble is, I don't have access to the addresses listed in the console. I have tried the mnemonic and private key approach, and the addresses that I see and fill with ether e.g. in Metamask, do not correspond with the addresses logged by Truffle. – user77510 Mar 12 at 12:35

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.