Skip to content

Commit

Permalink
Merge pull request #77 from makoto/infura
Browse files Browse the repository at this point in the history
Infura
  • Loading branch information
makoto authored Aug 27, 2017
2 parents 417ef0b + f12d92c commit 7e6026b
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 18 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ code 1234567890 is already registered. Claimed by 0x12ff7cfb557a7d0404b694da8d6
code 0987654321 is already registered. Claimed by 0xc7ce74c8c7f2e7c5e6d039c5a48fae053ad5c952
```

## Deploying and running on real network

For `ropsten` and `mainnet` it now deploys via Infura. Pass the extra to set deployment specific

```
--network $NETWORK --mnemonic $SECRET
```

NOTE: `ropsten` and `mainnet` uses different gasPrice. Check `truffle.js` file and `scripts/util/set_gas.js` for the detail.

### Essentials

See [Issues](https://github.com/makoto/blockparty/issues)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"react-tap-event-plugin": "^1.0.0",
"style-loader": "^0.13.1",
"truffle-contract": "^1.1.8",
"truffle-hdwallet-provider": "0.0.3",
"url-loader": "^0.5.7",
"web3": "^0.16.0",
"zeppelin-solidity": "0.0.6"
Expand Down
12 changes: 12 additions & 0 deletions scripts/balance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Display current balance of the provider address.

module.exports = function(callback) {
var address = '0x' + web3.currentProvider.wallet.getAddress().toString('hex');
console.log('Address', address)
web3.eth.getBalance(address, function(error,balance){
if (error) {
console.log('error', error);
}
console.log('Wallet address balance', web3.fromWei(balance,'ether').toNumber());
});
}
5 changes: 3 additions & 2 deletions scripts/change_owner.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
let arg = require('yargs').argv;
let fs = require('fs');
let Conference = artifacts.require("./Conference.sol");

let setGas = require('./util/set_gas');
if (!(arg.f && arg.t)) {
throw('usage: truffle exec scripts/change_owner.js -f original_owner.txt -t address_to_change.txt');
}
module.exports = async function() {
let gas = await setGas(web3);

let from = fs.readFileSync(arg.f, 'utf8').trim().split('\n')[0];
let to = fs.readFileSync(arg.t, 'utf8').trim().split('\n')[0];
Expand All @@ -16,7 +17,7 @@ module.exports = async function() {
if (owner != from) {
throw('current owner', owner, ' does not match with', from);
}
var result = await conference.transferOwnership(to, {from:from})
var result = await conference.transferOwnership(to, {from:from, gasPrice:gas})
let new_owner = await conference.owner.call();
if (new_owner != to) {
throw('new owner', new_owner, ' does not match with', to);
Expand Down
5 changes: 4 additions & 1 deletion scripts/repository.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
let fs = require('fs');
let setGas = require('./util/set_gas');
let ConfirmationRepository = artifacts.require("./ConfirmationRepository.sol");
let repository;
let arg = require('yargs').argv;

if (!(arg.i && arg.t)) {
throw('usage: truffle exec scripts/repository.js -t confirmation -i codes.txt');
}

module.exports = async function(callback) {
let gas = await setGas(web3);
let file = arg.i;
console.log('file', file)
switch (arg.t) {
Expand All @@ -26,7 +29,7 @@ module.exports = async function(callback) {
console.log('code', code, ' is already registered. Claimed by ', claimed);
}else{
var encrypted_code = await repository.encrypt.call(code);
var result = await repository.add(encrypted_code);
var result = await repository.add(encrypted_code, {gasPrice:gas});
console.log('Adding', code, ' as ', encrypted_code, ' with trx', result.tx);
}
}
Expand Down
17 changes: 17 additions & 0 deletions scripts/util/set_gas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = function(web3){
return new Promise(function(resolve,reject){
web3.version.getNetwork(function(err, network_id){
var gas;
console.log('network_id', network_id);
if (network_id == 1) { // mainnet
gas = 2000000000 // 2 gwei
}else if (network_id == 3) {
gas = 20000000000 // 20 gwei
}else{
gas = 1;
}
console.log('gas price', gas, web3.fromWei(gas, 'gwei'))
resolve(gas);
})
});
};
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function setup(){
console.log('Success')
}else{
console.log('The endspoint is not active. Falling back to read_only mode')
url = 'https://eth3.augur.net'
url = 'https://mainnet.infura.io'
read_only = true
}
}).error(function(error){
Expand Down
31 changes: 17 additions & 14 deletions truffle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
require('babel-register')
const yargs = require('yargs');
var provider, address;

if (yargs.argv.network == 'ropsten' || yargs.argv.network == 'mainnet') {
var providerURL = `https://${yargs.argv.network}.infura.io`
var HDWalletProvider = require('truffle-hdwallet-provider');
// todo: Think about more secure way
var mnemonic = yargs.argv.mnemonic;
provider = new HDWalletProvider(mnemonic, providerURL, 0);
address = "0x" + provider.wallet.getAddress().toString("hex");
console.log('Provider address', provider.getAddress());
console.log('Deploying to ', providerURL);
}

module.exports = {
networks: {
Expand All @@ -14,25 +26,16 @@ module.exports = {
gasPrice: 0x01
},
ropsten: {
host: "localhost",
port: 8545,
gasPrice: 20000000000, // 20 gwei,
provider: provider,
network_id: 3,
gas: 1990000,
gasPrice: 2000000000, // 2 gwei
},
kovan: {
host: 'localhost',
port: 8545,
// gas: 4700000,
network_id: 42
from: address
},
mainnet: {
host: "localhost",
port: 8545,
network_id: 1,
gas: 1990000,
gasPrice: 2000000000, // 2 gwei
from: '0xFa6F2D7cC987d592556ac07392b9d6395bfcc379'
from: address
}
}
};

0 comments on commit 7e6026b

Please sign in to comment.