Sitelet https://github.com/circlefin/stablecoin-evm/commit/a4a423de2968a085c42233fbfef762c285c1f440
Skip to content

Commit a4a423d

Browse files
committed
Update Truffle config to read the mnemonic and INFURA key from a file
Also add deployment instructions to README.md
1 parent b42cf04 commit a4a423d

6 files changed

Lines changed: 63 additions & 28 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ ganache-blockchain-log.txt
1616
.coverage_contracts
1717
yarn-error.log
1818
@types/generated/
19+
config.js

‎README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ To run tests and generate test coverage, run:
6969
$ yarn coverage
7070
```
7171

72+
## Deployment
73+
74+
Create a copy of the file `config.js.example`, and name it `config.js`. Enter
75+
the BIP39 mnemonic phrase and the INFURA API key to use for deployment in
76+
`config.js`:
77+
78+
```
79+
module.exports = {
80+
// BIP39 mnemonic phrase
81+
MNEMONIC: "YOUR_MNEMONIC_PHRASE",
82+
// INFURA API key
83+
INFURA_KEY: "YOUR_INFURA_API_KEY",
84+
};
85+
```
86+
87+
Do not check this file into the repo. To prevent accidental check-ins,
88+
`config.js` is in `.gitignore`.
89+
90+
Run `yarn migrate --network NETWORK`, where NETWORK is either `mainnet` or
91+
`ropsten`.
92+
7293
## Contracts
7394

7495
The implementation uses 2 separate contracts - a proxy contract

‎config.js.example‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
// BIP39 mnemonic phrase
3+
MNEMONIC: "",
4+
// INFURA API key
5+
INFURA_KEY: "",
6+
};

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"coverage": "truffle run coverage",
1919
"solhint": "solhint 'contracts/**/*.sol'",
2020
"precommit": "yarn typechain && yarn fmt && yarn typecheck && yarn lint && yarn solhint",
21-
"slither": "slither --solc-disable-warnings --disable-color --exclude-dependencies ."
21+
"slither": "slither --solc-disable-warnings --disable-color --exclude-dependencies .",
22+
"migrate": "truffle migrate --interactive"
2223
},
2324
"repository": {
2425
"type": "git",

‎truffle-config.js‎

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ require("ts-node/register/transpile-only");
44
Object.defineProperty(Error, "prepareStackTrace", { writable: false });
55

66
const HDWalletProvider = require("@truffle/hdwallet-provider");
7-
const mnemonic = "talisman";
87
const fs = require("fs");
8+
const path = require("path");
99

10-
// INFURA Setup - see validate/README.validate.md for more info
11-
let infuraKey = "none";
12-
try {
13-
infuraKey = fs.readFileSync("./validate/apikey.infura", "utf8");
14-
} catch (err) {
15-
console.log(
16-
"No Infura access token detected. Unit tests will still work. See ./validate/README.validate.md for more details."
17-
);
10+
// Read config file if it exists
11+
let config = { MNEMONIC: "", INFURA_KEY: "" };
12+
if (fs.existsSync(path.join(__dirname, "config.js"))) {
13+
config = require("./config.js");
1814
}
1915

2016
module.exports = {
@@ -40,25 +36,35 @@ module.exports = {
4036
port: 8545,
4137
network_id: "*", // Match any network id
4238
},
43-
// INFURA Setup
44-
infura_mainnet: {
45-
provider() {
46-
return new HDWalletProvider(
47-
mnemonic,
48-
"https://mainnet.infura.io/v3/" + infuraKey
49-
);
50-
},
39+
mainnet: {
40+
provider: infuraProvider("mainnet"),
5141
network_id: 1,
5242
},
43+
ropsten: {
44+
provider: infuraProvider("ropsten"),
45+
network_id: 3,
46+
},
5347
},
5448
mocha: {
5549
timeout: 10000, // prevents tests from failing when pc is under heavy load
56-
/*
57-
* To disable the spreadsheet verification tool ensure that
58-
* the reporter is set to 'Spec' by commenting/uncommenting the lines below.
59-
*/
6050
reporter: "Spec",
61-
// reporter: './verification/verification_reporter.js',
6251
},
6352
plugins: ["solidity-coverage"],
6453
};
54+
55+
function infuraProvider(network) {
56+
return () => {
57+
if (!config.MNEMONIC) {
58+
console.error("A valid MNEMONIC must be provided in config.js");
59+
process.exit(1);
60+
}
61+
if (!config.INFURA_KEY) {
62+
console.error("A valid INFURA_KEY must be provided in config.js");
63+
process.exit(1);
64+
}
65+
return new HDWalletProvider(
66+
config.MNEMONIC,
67+
`https://${network}.infura.io/v3/${config.INFURA_KEY}`
68+
);
69+
};
70+
}

‎validate/README.validate.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Note: Infura is a 3rd party provider.
1616
3. Create a new project - give it any name you want. Then whitelist the Token
1717
Proxy and the current Token Implementation addresses.
1818

19-
4. Create a local file `./validate/apikey.infura`. Copy the API Key from your
20-
project dashboard into the file and save.
19+
4. Follow the instructions under the "Deployment" section in `README.md` to
20+
configure the mnemonic phrase and the Infura API key in `config.js`.
2121

2222
# Configure Expected Values
2323

@@ -26,7 +26,7 @@ well as any other constants.
2626

2727
# Validation
2828

29-
Run `truffle exec ./validate/validate.js --network infura_mainnet`
29+
Run `truffle exec ./validate/validate.js --network mainnet`
3030

31-
You can replace `infura_mainnet` with any other network defined in `truffle.js`
32-
under `networks`.
31+
You can replace `mainnet` with any other network defined in `truffle.js` under
32+
`networks`.

0 commit comments

Comments
 (0)