-
Notifications
You must be signed in to change notification settings - Fork 45
/
4-genesis-token-type-NFT1-parent.ts
71 lines (61 loc) · 3.25 KB
/
4-genesis-token-type-NFT1-parent.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
60
61
62
63
64
65
66
67
68
69
70
71
/***************************************************************************************
*
* Example 4: Genesis for NFT1 Parent - These are used to create individual NFT1 children
*
* Instructions:
* (1) - Send some BCH to simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu
* or tBCH to slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l
* to fund the example.
* (2) - Run `tsc && node <file-name.js>` just before script execution
* (3) - Optional: Use vscode debugger w/ launch.json settings
*
* ************************************************************************************/
import { BigNumber } from "bignumber.js";
import * as BITBOXSDK from "bitbox-sdk";
import { GrpcClient } from "grpc-bchrpc-node";
import { BchdNetwork, GetRawTransactionsAsync, LocalValidator, SlpBalancesResult } from "../index";
const name = "My NFT1 Group";
const ticker = "NFT1 Group";
const documentUri = null;
const documentHash: Buffer|null = null;
const initialTokenQty = 1000000;
(async () => {
// // NETWORK: FOR MAINNET UNCOMMENT
const BITBOX = new BITBOXSDK.BITBOX();
const fundingAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- must be simpleledger format
const fundingWif = "L3gngkDg1HW5P9v5GdWWiCi3DWwvw5XnzjSPwNwVPN5DSck3AaiF"; // <-- compressed WIF format
const tokenReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- must be simpleledger format
const bchChangeReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- cashAddr or slpAddr format
// For unlimited issuance provide a "batonReceiverAddress"
const batonReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu";
// VALIDATOR SETUP: FOR REMOTE VALIDATION
const client = new GrpcClient(); //{ url: "bchd.ny1.simpleledger.io" });
const getRawTransactions: GetRawTransactionsAsync = async (txids: string[]) => {
const txid = txids[0];
const res = await client.getRawTransaction({ hash: txid, reversedHashOrder: true });
return [Buffer.from(res.getTransaction_asU8()).toString("hex")];
};
const logger = console;
const validator = new LocalValidator(BITBOX, getRawTransactions, logger);
const bchdNetwork = new BchdNetwork({ BITBOX, client, validator, logger });
// 1) Get all balances at the funding address.
const balances = await bchdNetwork.getAllSlpBalancesAndUtxos(fundingAddress) as SlpBalancesResult;
console.log("BCH balance:", balances.satoshis_available_bch);
// 2) Calculate the token quantity with decimal precision included
const initialTokenQtyBN = new BigNumber(initialTokenQty);
// 3) Set private keys
balances!.nonSlpUtxos.forEach(txo => txo.wif = fundingWif);
// 4) Use "simpleTokenGenesis()" helper method
const genesisTxid = await bchdNetwork.simpleNFT1ParentGenesis(
name,
ticker,
initialTokenQtyBN,
documentUri,
documentHash,
tokenReceiverAddress,
batonReceiverAddress,
bchChangeReceiverAddress,
balances!.nonSlpUtxos,
);
console.log("NFT1 Parent GENESIS txn complete:", genesisTxid);
})();