1

When deploying with Truffle how do you specify which wallet address to deploy with? I know if you're using web3 you can specify web3.eth.defaultAccount but how would I do this Truffle? I read somewhere to adjust your truffle.js file and add a from but it spits an error for me. How would truffle know which address I'm using to interact with it, e.g. me using MetaMask.

  • Can you paste your truffle.js file, the error, and tell us which network you want to deploy to ? – Julien Klepatch Nov 30 '17 at 22:50
  • I'm trying to deploy to testrpc. I'm just wondering how you can get the address that's interacting with a deployed contract – JorahFriendzone Nov 30 '17 at 23:06
2

By default, truffle uses the first account but in truffle.js you can specify the account address in the from property:

module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*', 
      from: '0x0c439ff0170Ab7d7Ef55f2993554eede7321c9b7'
    }
  }
}

If you want to deploy to a network other than localhost then you need to import a wallet provider and pass it your mnemonic.

Here's an example where the mnemonic is read from an environment variable and the provider is set to rinkeby testnet:

const HDWalletProvider = require('truffle-hdwallet-provider')

const mnemonic = process.env.MNEMONIC

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" 
    },
    rinkeby: {
      provider: new HDWalletProvider(mnemonic, 'https://rinkeby.infura.io'),
      network_id: '*',
      gas: 4500000,
      gasPrice: 25000000000
    }
  }
}

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.