-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate-map-tx.js
70 lines (64 loc) · 1.91 KB
/
create-map-tx.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
import { TurboFactory, defaultTurboConfiguration } from '@ardrive/turbo-sdk/node';
import fs from 'fs';
const mapName = 'b4m5.json';
const file = `../public/assets/maps/v2/snow/${mapName}`;
(async () => {
/**
* Generate a key from the arweave wallet.
*/
const jwk = JSON.parse(fs.readFileSync('.secrets/wallet.json', 'utf-8'));
/**
* Use the arweave key to create an authenticated turbo client
*/
const turboAuthClient = TurboFactory.authenticated({
privateKey: jwk,
...defaultTurboConfiguration,
});
/**
* Fetch the balance for the private key.
*/
const balance = await turboAuthClient.getBalance();
console.log('Balance:', balance);
/**
* Post local files to the Turbo service.
*/
console.log('Posting raw file to Turbo service...');
const filePath = new URL(file, import.meta.url).pathname;
const fileSize = fs.statSync(filePath).size;
const uploadResult = await turboAuthClient.uploadFile({
fileStreamFactory: () => fs.createReadStream(filePath),
fileSizeFactory: () => fileSize,
signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
dataItemOpts: {
tags: [
{
name: 'Data-Protocol',
value: 'warp-beavers-map',
},
{
name: 'Name',
value: mapName,
},
{
name: 'Map-Api-Version',
value: 'v2',
},
{
name: 'Terrain',
value: 'snow',
},
],
},
});
console.log(JSON.stringify(uploadResult, null, 2));
const transactionId = uploadResult.id;
console.log(transactionId);
/**
* Tops up a wallet with Credits using tokens.
* Default token is AR, using Winston as the unit.
*/
/* const topUpResult = await turboAuthClient.topUpWithTokens({
tokenAmount: WinstonToTokenAmount(100_000_000_000), // 0.0001 AR
});
console.log(JSON.stringify(topUpResult, null, 2));*/
})();