-
Notifications
You must be signed in to change notification settings - Fork 0
/
truffle.js
54 lines (46 loc) · 1.85 KB
/
truffle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Allows us to use ES6 in our migrations and tests.
require('babel-register')
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 = "At the edge of our hope, at the end of our time, we have chosen not only to believe in ourselves, but in each other";
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://ropsten.infura.io/c72adYaVKozBHnFEYqCy";
var engine = new ProviderEngine();
engine.addProvider(new WalletSubprovider(wallet, {}));
engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(providerUrl)));
// log new blocks
engine.on('block', function(block){
console.log('================================')
console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
console.log('================================')
})
// network connectivity error
engine.on('error', function(err){
// report connectivity errors
console.error(err.stack)
})
engine.start(); // Required by the provider engine.
module.exports = {
networks: {
ropsten: {
network_id: 3, // Official ropsten network id
provider: engine, // Use our custom provider
from: address, // Use the address we derived
gas: 3000000
}
},
rpc: {
// Use the default host and port when not using ropsten
host: "localhost",
port: 8545
}
};