truffle-hdwallet-provider
truffle-hdwallet-provider copied to clipboard
connecting Infura failed
I tried to deploy contract on ropsten network with truffle, metamask and infura.
truffle migrate --network ropsten
, but failed with the following error.
Using network 'ropsten'.
Running migration: 1_initial_migration.js
Deploying Migrations...
... 0xe89772d7bfae0395cd23bb951b045800f0fb886b7567032757caccd202ae1f07
Migrations: 0xd9c81f780c57f67488300999c3804036ccce7be7
Saving successful migration to network...
... 0x53e1bd330808f7f5b4f5a2a6e2f813c9bd16339f082e594197c6affc56654bc1
Saving artifacts...
Running migration: 2_deploy_contracts.js
Deploying SafeMathLib...
... 0xe88f7cb17beba180cdd0ac93f57f3e3a1cadbf610193380f843323c9661074d3
SafeMathLib: 0x26c183461e2a19b6c12cf0764bfae97085d2391d
Linking SafeMathLib to GeekToken
Deploying TestToken...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Unknown address - unable to sign transaction for this address: "0x6a07dFC88f9A027445621e80afdDc27Eabb23c4b"
My truffle.js is following:
var HDWalletProvider = require("truffle-hdwallet-provider");
var infura_apikey = "my_access_token_here";
var mnemonic = "twelve words for generating a serial ethereum address based on same seed";
module.exports = {
networks: {
development: {
host: "localhost", // Connect to geth on the specified
port: 8545,
network_id: "*", // Match any network id
gas: 4712388 // max gas
},
ropsten: {
provider: new HDWalletProvider(mnemonic, "https://ropsten.infura.io/"+infura_apikey),
network_id: 3,
gas: 2123456
},
kovan: {
provider: new HDWalletProvider(mnemonic, "https://kovan.infura.io/"+infura_apikey),
network_id: 42,
gas: 2123456
}
}
};
My truffle version is:
Truffle v3.4.11 (core: 3.4.11)
Solidity v0.4.15 (solc-js)
The 2_deploy_contracts.js is following:
var SafeMathLib = artifacts.require("./SafeMathLib.sol");
var TestToken = artifacts.require("./TestToken.sol");
var Tx = artifacts.require("./Tx.sol");
const initCoin = 11681168;
const tokenName = "Test@Ropsten";
const tokenSymbole = "tt";
let tokenIssuer = "0x6a07dFC88f9A027445621e80afdDc27Eabb23c4b";
const mFee = 10;
const bounty = 10000;
let creator = "0x4A224DEB89C3A98700502f623f5363882253bCDB";
module.exports = function(deployer, network, accounts) {
const amount = web3.toWei(10000000, 'ether');
deployer.deploy(SafeMathLib);
deployer.link(SafeMathLib, TestToken);
deployer.deploy(TestToken, initCoin, tokenName, tokenSymbole, {from: tokenIssuer, gas: 1333144})
.then(() => deployer.deploy(Tx, TestToken.address, tokenIssuer, mFee, bounty, {
from: creator,
gas: 1333144
})
)
};
What Happened?
Currently, HDWalletProvider manages only one address at a time. It's the first address generated from the mnemonic. Both tokenIssuer and creator should be equal to this address.
@7flash is mainnet always the first address generated? Mostly wondering how to go about deploying to ropsten if this is the case
does anyone have a solution to this one now? I am having the same problem.
I went to truffle console
and check the eth.getAddress()
its shows an address that I am not familiar with and it has 0 eth
.
The only solution that worked for me was to replace truffle-hdwallet-provider
with rather truffle-privatekey-provider. So rather than using mnemonic I gave in my private key
I had the same problem and worked around by creating a new provider with ethjs using web3 provider hook.
const sign = require('ethjs-signer').sign;
const HookedWeb3Provider = require("hooked-web3-provider");
...
networks: {
rinkebyInfura: {
provider: () => new HookedWeb3Provider({
host: "https://rinkeby.infura.io/v3/" + infuraKey,
transaction_signer: {
hasAddress: (address, cb) => cb(null, true),
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, '0x' + contractOwnerPrivateKey)),
}
}),
network_id: "4",
gas : 5000000,
from: contractOwner,
},
}
Though I still had issues with Infura when trying to deploy more than one contract with truffle migrate.
You can use private keys instead of mnemonic. https://github.com/trufflesuite/truffle-hdwallet-provider#private-keys
module.exports = {
networks: {
ropsten: {
provider: function() {
return new HDWalletProvider([
process.env.METAMASK_PRIVATE_KEY_1,
process.env.METAMASK_PRIVATE_KEY_2,
process.env.METAMASK_PRIVATE_KEY_3,
process.env.METAMASK_PRIVATE_KEY_4,
process.env.METAMASK_PRIVATE_KEY_5
], process.env.INFURA_API_ROPSTEN_ENDPOINT, 0, 5)
},
network_id: 3,
gas: 8000000
}
}
};
Any news on this?
You can use private keys instead of mnemonic. https://github.com/trufflesuite/truffle-hdwallet-provider#private-keys
module.exports = { networks: { ropsten: { provider: function() { return new HDWalletProvider([ process.env.METAMASK_PRIVATE_KEY_1, process.env.METAMASK_PRIVATE_KEY_2, process.env.METAMASK_PRIVATE_KEY_3, process.env.METAMASK_PRIVATE_KEY_4, process.env.METAMASK_PRIVATE_KEY_5 ], process.env.INFURA_API_ROPSTEN_ENDPOINT, 0, 5) }, network_id: 3, gas: 8000000 } } };
It help me a lot ! Thank you so much