-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdeploy.js
217 lines (198 loc) · 6.06 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import solc from "solc";
import fs from "fs";
import path from "path";
import { privateKey } from "./accounts/accounts.js";
import { Helper } from "./src/utils/helper.js";
import input from "input";
import { RPC } from "./src/core/network/rpc.js";
import { ethers } from "ethers";
import { DeployerConfig } from "./config/deployer_config.js";
const basePath = "src/core/deployer";
const provider = new ethers.JsonRpcProvider(RPC.RPCURL, RPC.CHAINID);
const maxError = 5;
let currentError = 0;
async function compileContract() {
console.log("Compiling Contract...");
const contractPath = path.resolve(basePath, "SkelDropHuntToken.sol");
const contractSource = fs.readFileSync(contractPath, "utf8");
console.log("Contract path :", contractPath);
const input = {
language: "Solidity",
sources: {
["SkelDropHuntToken.sol"]: {
content: contractSource,
},
},
settings: {
outputSelection: {
"*": {
"*": ["abi", "evm.bytecode"],
},
},
optimizer: {
enabled: true,
runs: 200,
},
evmVersion:
DeployerConfig.EVMVERSION != "default"
? DeployerConfig.EVMVERSION
: undefined,
},
};
const compiledContract = JSON.parse(solc.compile(JSON.stringify(input)));
const contract = compiledContract.contracts["SkelDropHuntToken.sol"];
const contractName = Object.keys(contract)[0];
const abi = contract[contractName].abi;
const bytecode = contract[contractName].evm.bytecode.object;
const abiPath = path.resolve(
`${basePath}/artifacts`,
`${contractName}.abi.json`
);
const bytecodePath = path.resolve(
`${basePath}/artifacts`,
`${contractName}.bytecode.txt`
);
fs.writeFileSync(abiPath, JSON.stringify(abi, null, 2));
fs.writeFileSync(bytecodePath, bytecode);
console.log(`Contract ${contractName} Compiled successfully!`);
console.log(`ABI saved to: ${abiPath}`);
console.log(`Bytecode saved to: ${bytecodePath}`);
return { abi, bytecode };
}
async function deployContract(
wallet,
abi,
bytecode,
name,
symbol,
initialSupply,
gas
) {
const factory = new ethers.ContractFactory(abi, bytecode, wallet);
const initialSupplyBigNumber = ethers.parseUnits(initialSupply, 18);
console.log(
`Deploying Contract...
Name : ${name}
Symbol : ${symbol}
Supply : ${initialSupplyBigNumber}
`
);
try {
if (!gas) {
gas = BigInt(DeployerConfig.GASLIMIT);
} else {
gas = gas + BigInt(DeployerConfig.GASLIMIT);
}
const fee = await provider.getFeeData();
const customGasPrice = ethers.parseUnits(
DeployerConfig.GWEIPRICE.toString(),
"gwei"
);
const gasPrice =
fee.gasPrice > customGasPrice ? fee.gasPrice : customGasPrice;
console.log("Deploying using gasLimit : ", gas);
console.log("Deploying using gasPrice : ", gasPrices);
const contract = await factory.deploy(
name,
symbol,
initialSupplyBigNumber,
{
gasLimit: gas,
gasPrice: gasPrice,
}
);
await confirmDeployment(contract);
} catch (error) {
console.warn(
`Deployment attempt failed, ${
currentError != maxError ? "Retrying" : "Max Error Reached"
}`
);
console.error(error.message);
if (currentError != maxError) {
currentError += 1;
await deployContract(
wallet,
abi,
bytecode,
name,
symbol,
initialSupply,
gas
);
}
}
}
async function confirmDeployment(contract) {
console.log(
`Contract Deployment Tx Sent: ${RPC.EXPLORER}tx/${
contract.deploymentTransaction().hash
}, Waiting for Block Confirmation`
);
const result = await contract.deploymentTransaction().wait();
console.log(`\nContract Adress: ${result.contractAddress}`);
console.log(
`Contract Address On Explorer : ${RPC.EXPLORER}address/${result.contractAddress}`
);
console.log(
`Please Verify Your Contract Using This Detail :
Contract Verification Link : ${RPC.EXPLORER}address/${result.contractAddress}/contract-verification
Contract License : MIT License (MIT)
Verification methid (Compiler Type) : Solidity (Single File)
Compiler : v0.8.28
EVM Version : ${DeployerConfig.EVMVERSION}
Optimization Enabled : TRUE (200)
Contract Code : Copy Paste Everything from /src/core/deployer/SkelDropHuntToken.sol
Thanks for using our EVM TX DEPLOYER tool
Regards: Widiskel (Skel Drop Hunt)
`
);
}
(async () => {
try {
console.log("Contract Deployer Bot");
console.log();
console.log("By : Widiskel");
console.log("Follow On : https://github.com/Widiskel");
console.log("Join Channel : https://t.me/skeldrophunt");
console.log("Dont forget to run git pull to keep up to date");
console.log();
Helper.showSkelLogo();
console.log();
if (privateKey.length == 0)
throw Error("Please input your account first on accounts.js file");
let ctx = "Account List \n";
for (const item of privateKey) {
ctx += `${privateKey.indexOf(item) + 1}. Account ${
privateKey.indexOf(item) + 1
}\n`;
}
ctx += `\n \nSelect Account To Deploy Contract : `;
const opt = await input.text(ctx);
if (!privateKey[opt - 1]) throw Error(`Invalid Input`);
const acc = privateKey[opt - 1];
let wallet;
const data = acc;
const type = Helper.determineType(data);
if (type == "Secret Phrase") {
/**
* @type {Wallet}
*/
wallet = ethers.Wallet.fromPhrase(data, provider);
} else if (type == "Private Key") {
/**
* @type {Wallet}
*/
wallet = new ethers.Wallet(data.trim(), provider);
} else {
throw Error("Invalid account Secret Phrase or Private Key");
}
const name = await input.text("Enter token name: ");
const symbol = await input.text("Enter token symbol: ");
const initialSupply = await input.text("Enter initial supply: ");
const { abi, bytecode } = await compileContract();
await deployContract(wallet, abi, bytecode, name, symbol, initialSupply);
} catch (error) {
console.log("Error During executing bot", error);
}
})();