-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
35 lines (28 loc) · 1 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
const path = require('path');
const fs = require('fs');
const mnemonicFile = path.resolve(__dirname, 'config', 'mnemonic.txt');
const mnemonic = fs.readFileSync(mnemonicFile, 'utf8');
const infuraFile = path.resolve(__dirname, 'config', 'infura.txt');
const infuraUrl = fs.readFileSync(infuraFile, 'utf8');
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const {interface, bytecode} = require('./compile');
const provider = new HDWalletProvider(
mnemonic,
infuraUrl
);
const web3 = new Web3(provider);
const deploy = async() => {
try {
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account ', accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({data: '0x' + bytecode})
.send({gas: '1000000', from: accounts[0]});
console.log(interface);
console.log('Contract deployed to ', result.options.address);
} catch (err) {
console.log(err);
}
};
deploy();