File tree 5 files changed +22
-7
lines changed
5 files changed +22
-7
lines changed Original file line number Diff line number Diff line change
1
+ PRIVATE_KEY = xxxxxxxxxxxxxxxx
2
+ INFURA_ID = yyyyyyyy
Original file line number Diff line number Diff line change
1
+ PRIVATE_KEY = xxxxxxxxxxxxxxxx
2
+ INFURA_ID = yyyyyyyy
Original file line number Diff line number Diff line change @@ -40,15 +40,25 @@ truffle 开发框架提供了很多功能,简化了我们的开发、编译、
40
40
npm install -g truffle
41
41
```
42
42
43
- 2 . 测试合约
43
+ 2 . 配置 .env
44
+
45
+ ``` sh
46
+ cp .env.example .env
47
+
48
+ # # 修改 .env 中的 INFURA_ID 和 PRIVATE_KEY 为实际的值
49
+ PRIVATE_KEY=xxxxxxxxxxxxxxxx
50
+ INFURA_ID=yyyyyyyy
51
+ ```
52
+
53
+ 3 . 测试合约
44
54
``` bash
45
55
truffle test
46
56
```
47
57
48
58
这里,使用 "truffle test" 后,truffle 会启动内置的 test 网络,同时执行 测试 test 目录下的所有脚本,如果想单独测试某个脚本,可以
49
59
执行 "truffle test ./test/simpletoken.js"
50
60
51
- 3 . 编译合约
61
+ 4 . 编译合约
52
62
``` bash
53
63
truffle compile
54
64
```
@@ -61,7 +71,7 @@ Compiling .\contracts\SimpleToken.sol...
61
71
Writing artifacts to .\b uild\c ontracts
62
72
```
63
73
64
- 4 . 部署合约
74
+ 5 . 部署合约
65
75
66
76
在 truffle-config.js 里面,可以配置 truffle 使用的以太网络,其中就包括 truffle test 使用的 "test" 网络。
67
77
这里,直接执行 truffle migrate 报没有找到 test 网络,因为 truffle 不会启动内置的 test 网络。所以这里我们使用 kovan 进行 truffle 合约部署
Original file line number Diff line number Diff line change 13
13
"author" : " " ,
14
14
"license" : " ISC" ,
15
15
"dependencies" : {
16
+ "dotenv" : " ^16.0.0" ,
16
17
"truffle" : " ^5.3.6" ,
17
18
"truffle-hdwallet-provider" : " ^1.0.17" ,
18
19
"web3" : " ^1.3.6"
Original file line number Diff line number Diff line change 1
1
const fs = require ( 'fs' )
2
2
const HDWalletProvider = require ( 'truffle-hdwallet-provider' )
3
3
4
- const mnemonic = fs . readFileSync ( './sk.txt ') . toString ( ) . trim ( )
4
+ require ( 'dotenv ') . config ( ) ;
5
5
6
6
module . exports = {
7
7
// Uncommenting the defaults below
@@ -30,7 +30,7 @@ module.exports = {
30
30
ropsten : {
31
31
provider : ( ) =>
32
32
new HDWalletProvider (
33
- mnemonic ,
33
+ process . env . PRIVATE_KEY ,
34
34
'https://ropsten.infura.io/v3/0aae8358bfe04803b8e75bb4755eaf07'
35
35
) ,
36
36
network_id : '*' ,
@@ -40,15 +40,15 @@ module.exports = {
40
40
kovan : {
41
41
provider : ( ) =>
42
42
new HDWalletProvider (
43
- mnemonic ,
43
+ process . env . PRIVATE_KEY ,
44
44
'https://kovan.infura.io/v3/0aae8358bfe04803b8e75bb4755eaf07'
45
45
) ,
46
46
network_id : '*' ,
47
47
} ,
48
48
rinkeby : {
49
49
provider : ( ) =>
50
50
new HDWalletProvider (
51
- mnemonic ,
51
+ process . env . PRIVATE_KEY ,
52
52
'https://rinkeby.infura.io/v3/0aae8358bfe04803b8e75bb4755eaf07'
53
53
) ,
54
54
network_id : '*' ,
You can’t perform that action at this time.
0 commit comments