/
scrap.ts
59 lines (54 loc) · 1.69 KB
/
scrap.ts
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
import "./env";
import {Account, NetworkType, PublicAccount} from "symbol-sdk";
import {MetalServiceV2, SymbolService} from "metal-on-symbol";
import assert from "assert";
// Edit here -------------
const nodeUrl = process.env.TEST_NODE_URL;
const privateKey = process.env.TEST_PRIVATE_KEY; // The account will be signer/source/target
const metalId = process.argv[2];
// -----------------------
assert(nodeUrl);
const symbolService = new SymbolService({ node_url: nodeUrl });
const metalService = new MetalServiceV2(symbolService);
assert(privateKey);
const signerAccount = Account.createFromPrivateKey(privateKey, NetworkType.TEST_NET);
const scrapMetal = async (
metalId: string,
sourcePubAccount: PublicAccount,
targetPubAccount: PublicAccount,
signerAccount: Account,
cosignerAccounts: Account[]
) => {
const metadataEntry = (await metalService.getFirstChunk(metalId)).metadataEntry;
const txs = await metalService.createScrapTxs(
metadataEntry.metadataType,
sourcePubAccount,
targetPubAccount,
metadataEntry.targetId,
metadataEntry.scopedMetadataKey,
);
if (!txs) {
throw Error("Transaction creation error.");
}
const batches = await symbolService.buildSignedAggregateCompleteTxBatches(
txs,
signerAccount,
cosignerAccounts,
);
const errors = await symbolService.executeBatches(batches, signerAccount);
if (errors) {
throw Error("Transaction error.");
}
};
scrapMetal(
metalId,
signerAccount.publicAccount,
signerAccount.publicAccount,
signerAccount,
[]
).then(() => {
console.log(`Scrapped!`);
}).catch((e) => {
console.error(e);
process.exit(1);
});