-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunInitialDeploy.ts
More file actions
93 lines (74 loc) · 2.99 KB
/
runInitialDeploy.ts
File metadata and controls
93 lines (74 loc) · 2.99 KB
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
import * as fs from 'fs';
import { AeSdk, MemoryAccount, Node, CompilerHttp, Contract, getFileSystem } from '@aeternity/aepp-sdk';
// Path to the contract source file
const AIRDROP_TOKEN_MINTER_SOURCE = "./airdrop-contract/contracts/AirdropTokenMinter.aes";
// Read configuration from deploy-config.json
const loadConfig = () => {
try {
const configData = fs.readFileSync('./deploy-config.json', 'utf8');
return JSON.parse(configData);
} catch (error) {
console.error('Error reading config file:', error);
process.exit(1);
}
};
const deployContract = async () => {
// Load configuration
const config = loadConfig();
const { privateKey, tokenName, tokenSymbol } = config;
if (!privateKey || privateKey === 'YOUR_PRIVATE_KEY_HERE') {
console.error('Please provide a valid private key in deploy-config.json');
process.exit(1);
}
if (!tokenName || tokenName === 'YOUR_TOKEN_NAME_HERE') {
console.error('Please provide a valid token name in deploy-config.json');
process.exit(1);
}
if (!tokenSymbol || tokenSymbol === 'YOUR_TOKEN_SYMBOL_HERE') {
console.error('Please provide a valid token symbol in deploy-config.json');
process.exit(1);
}
console.log(`Deploying contract with token name: ${tokenName} and symbol: ${tokenSymbol}`);
try {
// Initialize SDK with the provided private key
const account = new MemoryAccount(privateKey);
const node = new Node('https://mainnet.aeternity.io');
const compiler = new CompilerHttp('https://compiler.aeternity.io');
const aeSdk = new AeSdk({
nodes: [{ name: 'mainnet', instance: node }],
accounts: [account],
compiler,
});
// Set the account as default
await aeSdk.addAccount(account, { select: true });
// Get the contract source code
const sourceCode = fs.readFileSync(AIRDROP_TOKEN_MINTER_SOURCE, 'utf8');
// A filesystem object must be passed to the compiler if the contract uses custom includes
const fileSystem = await getFileSystem(AIRDROP_TOKEN_MINTER_SOURCE);
// Initialize the contract instance
const contract = await Contract.initialize({
client: aeSdk,
sourceCode,
fileSystem,
});
// Deploy the contract
console.log('Deploying contract...');
const deployResult = await contract.deploy([tokenName, tokenSymbol]);
console.log('Contract deployed successfully!');
console.log('Contract address:', deployResult.address);
console.log('Transaction hash:', deployResult.transaction);
// Save the contract address to a file for future reference
fs.writeFileSync('./contract-address.json', JSON.stringify({
address: deployResult.address,
transaction: deployResult.transaction,
deployedAt: new Date().toISOString()
}, null, 2));
console.log('Contract address saved to contract-address.json');
return deployResult;
} catch (error) {
console.error('Error deploying contract:', error);
process.exit(1);
}
};
// Execute the deployment
deployContract().catch(console.error);