forked from CloudhGamer/OG-Lab-Auto-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
29 lines (23 loc) · 989 Bytes
/
deploy.js
File metadata and controls
29 lines (23 loc) · 989 Bytes
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
require('colors');
const ethers = require('ethers');
const { generateContractCode } = require('./contractCode');
async function deployContract(network, name, symbol, supply) {
try {
const provider = new ethers.JsonRpcProvider(network.rpcUrl);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
console.log(`\nDeploying contract to ${network.name}...`.yellow);
const { bytecode, abi } = generateContractCode(name, symbol, supply);
const factory = new ethers.ContractFactory(abi, bytecode, wallet);
const contract = await factory.deploy();
console.log(`\nContract deployed successfully!`.green);
console.log(`Contract address: ${contract.target}`.cyan);
console.log(
`Explorer URL: ${network.explorer}/address/${contract.target}`.blue
);
return contract.target;
} catch (error) {
console.error(`Error deploying contract: ${error.message}`.red);
process.exit(1);
}
}
module.exports = { deployContract };