-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy-solc-0.4.js
63 lines (38 loc) · 1.56 KB
/
deploy-solc-0.4.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
const Web3 = require('web3')
const compiler = require('./compile-sol-file')
let web3 = new Web3(Web3.givenProvider || "ws://localhost:33333");
//let web3 = new Web3("http://127.0.0.1:8545")
//let web3 = new Web3("http://127.0.0.1:7545")
let returnAccounts = async () => {
return await web3.eth.getAccounts((error,accounts) => {
})
}
let deploy = async (contractFileName, contractName, contractArguments) => {
// later add the contractArguments part.
//TODO: add the support for passing arguments when creating the contract.
return await returnAccounts().then((accounts) => {
output = compiler(contractFileName)
//console.log(output.contracts)
var jsonInterface = JSON.parse(output.contracts[":"+contractName].interface)
var data = output.contracts[":"+contractName].bytecode
var contract = new web3.eth.Contract(jsonInterface, {gasPrice: '12345678', from: accounts[0]})
return {
data: data,
contract: contract,
accounts: accounts
}
}).then(res => {
data = res.data
contract = res.contract
accounts = res.accounts
return contract.deploy({data: data}).send({
from: accounts[0],
gas: 1500000,
gasPrice: '3000000000'
}, function(error, transactionHash){
}).then(deployedContract => {
return deployedContract.options.address
})
})
}
module.exports = deploy;