-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
86 lines (65 loc) · 2.24 KB
/
deploy.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var fs = require('fs');
var solc = require('solc');
var Web3 = require('web3');
var assert = require('assert');
var config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
// 1 - initialize
var Web3 = require('web3');
var web3;
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
if (config.environment == "live")
web3 = new Web3(new Web3.providers.HttpProvider(config.rpc.live));
else (config.environment == "dev")
web3 = new Web3(new Web3.providers.HttpProvider(config.rpc.test));
}
//Config
var file = './contracts/Token.sol';
var contractName = 'ZilleriumToken';
console.log('Reading contract file');
fs.readFile(file, function(err, result){
assert.equal(err,null);
var source = result.toString();
assert.notEqual(source.length,0);
var output = solc.compile(source, 1); // 1 activates the optimiser
//console.log('OUTPUT: ');
//console.log(output);
abi = JSON.parse(output.contracts[contractName].interface);
var bytecode = output.contracts[contractName].bytecode;
var tempContract = web3.eth.contract(abi);
var alreadyCalled = false;
var isTestContract = true;
var creator = accounts[0];
var buyer = accounts[1];
var foundation = accounts[2];
var founders = accounts[3];
var devs = accounts[4];
var daoFund = accounts[5];
console.log('Deploy contract');
tempContract.new(
isTestContract,
startBlock,
endBlock,
daoFund,
foundation,
founders,
devs,
{
from: creator,
gas: 3000000,
data: bytecode
},
function(err, c){
assert.equal(err, null);
web3.eth.getTransactionReceipt(c.transactionHash, function(err, result){
assert.equal(err, null);
console.log('Contract address: ');
console.log(result.contractAddress);
contractAddress = result.contractAddress;
contract = web3.eth.contract(abi).at(result.contractAddress);
//console.log('Contract: ');
//console.log(contract);
});
});
});