generated from Envoy-VC/arweave-react-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
64 lines (57 loc) · 1.57 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
import Irys from '@irys/sdk';
import * as dotenv from 'dotenv';
dotenv.config({ path: '.env.local' });
import fs from 'fs';
import path from 'path';
function getTotalSize(folderPath) {
let totalSize = 0;
function traverseDirectory(directoryPath) {
const files = fs.readdirSync(directoryPath);
files.forEach((file) => {
const filePath = path.join(directoryPath, file);
const stats = fs.statSync(filePath);
if (stats.isFile()) {
totalSize += stats.size;
} else if (stats.isDirectory()) {
traverseDirectory(filePath);
}
});
}
traverseDirectory(folderPath);
return totalSize;
}
const deploy = async () => {
const url = 'https://devnet.irys.xyz';
const providerUrl = 'https://mumbai.rpc.thirdweb.com/';
const token = 'matic';
const irys = new Irys({
url,
token,
key: process.env.PK,
config: { providerUrl },
});
await irys.ready();
const folderToUpload = './dist';
const balance = irys.utils.fromAtomic(await irys.getLoadedBalance());
console.log('Current Balance: ', balance);
const cost = irys.utils.fromAtomic(
await irys.getPrice(getTotalSize(folderToUpload))
);
console.log('Cost to Upload: ', cost);
try {
const receipt = await irys.uploadFolder(folderToUpload, {
indexFile: 'index.html',
});
console.log(`Files uploaded. Manifest ID: ${receipt.id}`);
const balanceAfterUpload = irys.utils.fromAtomic(
await irys.getLoadedBalance()
);
console.log('Balance after upload: ', balanceAfterUpload);
} catch (e) {
console.log('Error uploading file ', e);
}
};
deploy().catch((err) => {
console.error(err);
process.exit(1);
});