-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodesetup_id101.js
54 lines (53 loc) · 2.19 KB
/
nodesetup_id101.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
Web3 = require('web3');
require('dotenv').config();
const AWS = require('aws-sdk');
const s3 = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
});
const request = require('request');
request('https://s3.ap-south-1.amazonaws.com/smart-contracts-blockchain/candidate_'+process.argv[2]+'.json', { json: true }, (err, res, body) => {
if (err) { return console.log(err); }
var candidate_data = body;
var fs = require("fs");
var prompt = require('prompt');
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
console.log(web3.eth.accounts);
code = fs.readFileSync('Voting.sol').toString();
solc = require('solc');
compiledCode = solc.compile(code);
abiDefinition = JSON.parse(compiledCode.contracts[':Voting'].interface);
VotingContract = web3.eth.contract(abiDefinition);
byteCode = compiledCode.contracts[':Voting'].bytecode;
deployedContract = VotingContract.new(candidate_data['candidateDetails']['candidates'],web3.eth.accounts,{data: byteCode, from: web3.eth.accounts[0], gas: 4700000});
setTimeout(function(){
contractInstance = VotingContract.at(deployedContract.address);
obj = {'contract':contractInstance.address};
s3.putObject({Bucket: 'smart-contracts-blockchain',Key: 'contract_'+process.argv[2]+'.json',Body: JSON.stringify(obj),ACL:'public-read' ,ContentType: "application/json"},function(err,data){console.log(JSON.stringify(err));});
console.log("contractInstance address:" + contractInstance.address);
var fs = require('fs');
// fs.writeFile("./nodesetup_output.txt", contractInstance.address + " " + web3.eth.accounts, function(err) {
// if(err) {
// return console.log(err);
// }
//
// console.log("nodesetup_output saved!");
// });
fs.unlink('nodesetup_output.txt', (err) => {
if (err) throw err;
console.log('successfully deleted');
});
var logger = fs.createWriteStream('nodesetup_output.txt', {
flags: 'a' // 'a' means appending (old data will be preserved)
});
logger.write(contractInstance.address+'\n');
web3.eth.accounts.map(function(x){
logger.write(x+'\n');
});
logger.end();
prompt.start();
prompt.get(['Enter to quit'], function (err, result) {
console.log('Finished');
});
}, 5000);
});