-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-deploy.js
46 lines (33 loc) · 1.32 KB
/
02-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
39
40
41
42
43
44
45
46
let {bytecode, interface} = require('./01-compile')
//1. 引入web3
let Web3 = require('web3')
//let HDWalletProvider = require('truffle-hdwallet-provider')
//2. new 一个web3实例
let web3 = new Web3()
//3. 设置网络
let terms = 'say medal twin sibling entire clap youth height staff ball bag inquiry'
// let netIp = 'https://ropsten.infura.io/v3/02cd1e3c295c425597fa105999493baa'
let netIp = 'http://127.0.0.1:8545'
//let provider = new HDWalletProvider(terms, netIp)
// web3.setProvider('HTTP://192.168.28.30:7545')
web3.setProvider('HTTP://127.0.0.1:8545')
// web3.setProvider(provider)
//const web3 = new Web3(Web3.givenProvider || "http://localhost:7545");
//1. 拼接合约数据 interface
let contract = new web3.eth.Contract(JSON.parse(interface))
let deploy = async () => {
//1. 现获取所有的账户
let accounts = await web3.eth.getAccounts()
console.log('accounts :', accounts)
//2. 执行部署
let instance = await contract.deploy({
data: bytecode, //合约的bytecode
// arguments: ['HelloWorld'] //给构造函数传递参数,使用数组
}).send({
from: accounts[0],
gas: '3000000', //不要用默认值,一定要写大一些, 要使用单引号
//gasPrice: '1',
})
console.log('instance address :', instance.options.address)
}
deploy()