-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateContracts.js
executable file
·86 lines (78 loc) · 2.07 KB
/
createContracts.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const { bufferToHex, ripemd160 } = require("ethereumjs-util");
const Earth = require("../build/contracts/Earth");
const Air = require("../build/contracts/Air");
const outdir = process.argv[2] || ".";
const airOutFile = path.join(outdir, "Air.json");
const earthOutFile = path.join(outdir, "Earth.json");
const testnetCO2 = "0xF64fFBC4A69631D327590f4151B79816a193a8c6";
const testnetGOL = "0x1f89Fb2199220a350287B162B9D0A330A2D2eFAD";
const gameMaster = "0x0d56caf1ccb9eddf27423a1d0f8960554e7bc9d5"; // shared with SDP peeps
const replaceAll = (str, find, replace) =>
str.replace(new RegExp(find, "g"), replace.replace("0x", "").toLowerCase());
// deploy air
let airCode = Air.deployedBytecode;
// replace token address placeholder to real token address
airCode = replaceAll(
airCode,
"1231111111111111111111111111111111111123",
testnetCO2
);
airCode = replaceAll(
airCode,
"2341111111111111111111111111111111111234",
testnetGOL
);
airCode = replaceAll(
airCode,
"5671111111111111111111111111111111111567",
gameMaster
);
const airContractAddr = bufferToHex(ripemd160(airCode));
fs.writeFileSync(
airOutFile,
JSON.stringify(
{ address: airContractAddr, code: airCode, abi: Air.abi },
null,
2
)
);
console.log("Air exported to", airOutFile);
// only needed for testnet deployment
let earthCode = Earth.deployedBytecode;
earthCode = replaceAll(
earthCode,
"1231111111111111111111111111111111111123",
testnetCO2
);
earthCode = replaceAll(
earthCode,
"2341111111111111111111111111111111111234",
testnetGOL
);
earthCode = replaceAll(
earthCode,
"4561111111111111111111111111111111111456",
airContractAddr
);
earthCode = replaceAll(
earthCode,
"5671111111111111111111111111111111111567",
gameMaster
);
const earthContractAddr = bufferToHex(ripemd160(earthCode));
fs.writeFileSync(
earthOutFile,
JSON.stringify(
{
address: earthContractAddr,
code: earthCode,
abi: Earth.abi
},
null,
2
)
);
console.log("Earth exported to", earthOutFile);