-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdeployContract.js
More file actions
69 lines (59 loc) · 1.89 KB
/
deployContract.js
File metadata and controls
69 lines (59 loc) · 1.89 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var fs = require('fs');
var config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
var provider = require('./helpers/basicauthhttpprovider');
var Web3 = require('web3');
var web3;
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
if (config.environment == "live")
web3 = new Web3(new provider(config.smartContract.rpc[config.environment], config.smartContract.rpc.user, config.smartContract.rpc.pass));
else
web3 = new Web3(new Web3.providers.HttpProvider(config.smartContract.rpc[config.environment]));
}
var contractABI = config.smartContract.abi;
var compiled = config.smartContract.bin;
//estimateGas();
deployContract();
function estimateGas() {
web3.eth.defaultAccount = web3.eth.accounts[0];
var balance = web3.eth.getBalance(web3.eth.defaultAccount);
console.log(balance.toString(10));
console.log(balance.toNumber());
console.log(balance);
var result = web3.eth.estimateGas({
from: web3.eth.defaultAccount,
data: compiled
});
console.log(result);
}
function deployContract() {
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[0];
var gasWillUsed = web3.eth.estimateGas({
from: web3.eth.defaultAccount,
data: compiled
});
console.log(gasWillUsed);
gasWillUsed += 30000;
var phonetoaddressContract = web3.eth.contract(contractABI);
phonetoaddressContract.new(
{
data: compiled,
gas: gasWillUsed,
from: web3.eth.defaultAccount
}, function(err, contract) {
if(!err) {
if (typeof contract.address != 'undefined') {
console.log("contract:");
console.log(contract);
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
} else {
console.log(contract.transactionHash);
}
} else {
console.log("error:");
console.log(err);
}
});
};