-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.js
38 lines (32 loc) · 1.13 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
var solc = require('solc');
var Web3 = require('web3');
var fs = require('fs');
var path = require('path');
var BLOCKCHAIN_URL = "http://localhost:8545";
var web3 = new Web3(new Web3.providers.HttpProvider(BLOCKCHAIN_URL));
var contractFile = path.join(__dirname, 'Ethsurance.sol');
var code = fs.readFileSync(contractFile).toString();
var compiledCode = solc.compile(code);
var abiDefinition = JSON.parse(compiledCode.contracts[':Ethsurance'].interface);
var byteCode = compiledCode.contracts[':Ethsurance'].bytecode;
var contract = new web3.eth.Contract(abiDefinition);
web3.eth.getAccounts().then(function(accounts) {
console.log(accounts);
contract.deploy({
data: byteCode
}).send({
from: accounts[0],
gas: 4700000
})
.then(function(newContractInstance){
var contract = {
address: newContractInstance.options.address,
abi: abiDefinition
}
var contractPath = path.join(__dirname, 'src', 'static', 'contract.json');
var contractContent = JSON.stringify(contract);
fs.writeFile(contractPath, contractContent, 'utf8', function (err) {
if (err) return console.log(err);
});
});
});