|
1 | 1 | const chalk = require('chalk'); |
| 2 | +const util = require('util'); |
2 | 3 |
|
3 | | -const deployContract = async (web3, contractDetails) => { |
| 4 | +const deployContract = async (web3, contractDetails, args) => { |
4 | 5 | const deployingAccount = (await web3.eth.getAccounts())[0]; |
5 | 6 |
|
6 | 7 | // Create contract instance |
7 | 8 | const contract = new web3.eth.Contract(contractDetails.abi, { |
8 | | - data: contractDetails.bytecode, |
| 9 | + data: contractDetails.bytecode |
9 | 10 | }); |
10 | 11 |
|
11 | 12 | // Estimate gas |
12 | 13 | const gasLimit = await web3.eth.estimateGas({ |
13 | | - data: contractDetails.bytecode, |
| 14 | + data: contractDetails.bytecode |
14 | 15 | }); |
15 | 16 |
|
16 | 17 | // Deploy contract |
17 | | - return await contract.deploy().send({ |
| 18 | + return await contract.deploy({ arguments: args }).send({ |
18 | 19 | from: deployingAccount, |
19 | | - gasLimit: gasLimit, |
| 20 | + gasLimit: gasLimit |
20 | 21 | }); |
21 | 22 | }; |
22 | 23 |
|
| 24 | +const contractJsonDAVToken = require('../../contracts/DAVToken.json'); |
| 25 | +const contractJsonIdentity = require('../../contracts/Identity.json'); |
| 26 | +const contractJsonBasicMission = require('../../contracts/BasicMission.json'); |
| 27 | + |
23 | 28 | const deployContracts = async web3 => { |
24 | | - const DAVToken = await deployContract( |
25 | | - web3, |
26 | | - require('../../contracts/DAVToken.json'), |
27 | | - ); |
28 | | - console.log( |
29 | | - 'DAVToken contract: ' + chalk.green.bold(DAVToken.options.address), |
30 | | - ); |
| 29 | + try { |
| 30 | + const contractDAVToken = await deploySingleContract(web3, contractJsonDAVToken, null); |
| 31 | + const contractIdentity = await deploySingleContract(web3, contractJsonIdentity, [contractDAVToken.options.address]); |
| 32 | + const contractBasicMission = await deploySingleContract(web3, contractJsonBasicMission, [contractIdentity.options.address, contractDAVToken.options.address]); |
| 33 | + } catch (err) { |
| 34 | + console.error(util.inspect(err)); |
| 35 | + } |
31 | 36 | }; |
32 | 37 |
|
| 38 | +async function deploySingleContract(web3, contractJson, args) { |
| 39 | + console.log(`Deploying ${contractJson.contractName}...`); |
| 40 | + const contract = await deployContract(web3, contractJson, args); |
| 41 | + console.log(`${contractJson.contractName} contract: ${chalk.green.bold(contract.options.address)}`); |
| 42 | + return contract; |
| 43 | +} |
| 44 | + |
33 | 45 | module.exports = { |
34 | | - deployContracts, |
| 46 | + deployContracts |
35 | 47 | }; |
0 commit comments