-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate-mint.ts
More file actions
81 lines (72 loc) · 2.09 KB
/
create-mint.ts
File metadata and controls
81 lines (72 loc) · 2.09 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
import "dotenv/config";
import {
Keypair,
ComputeBudgetProgram,
PublicKey,
Transaction,
sendAndConfirmTransaction,
} from "@solana/web3.js";
import {
createRpc,
getBatchAddressTreeInfo,
selectStateTreeInfo,
CTOKEN_PROGRAM_ID,
} from "@lightprotocol/stateless.js";
import {
createMintInstruction,
createTokenMetadata,
} from "@lightprotocol/compressed-token";
import { homedir } from "os";
import { readFileSync } from "fs";
const COMPRESSED_MINT_SEED = Buffer.from("compressed_mint");
function findMintAddress(mintSigner: PublicKey): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[COMPRESSED_MINT_SEED, mintSigner.toBuffer()],
CTOKEN_PROGRAM_ID
);
}
// devnet:
// const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`;
// const rpc = createRpc(RPC_URL);
// localnet:
const rpc = createRpc();
const payer = Keypair.fromSecretKey(
new Uint8Array(
JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8"))
)
);
(async function () {
const mintSigner = Keypair.generate();
const addressTreeInfo = getBatchAddressTreeInfo();
const stateTreeInfo = selectStateTreeInfo(await rpc.getStateTreeInfos());
const [mintPda] = findMintAddress(mintSigner.publicKey);
const validityProof = await rpc.getValidityProofV2(
[],
[{ address: mintPda.toBytes(), treeInfo: addressTreeInfo }]
);
const ix = createMintInstruction(
mintSigner.publicKey,
9,
payer.publicKey,
null,
payer.publicKey,
validityProof,
addressTreeInfo,
stateTreeInfo,
createTokenMetadata(
"Example Token",
"EXT",
"https://example.com/metadata.json"
)
);
const tx = new Transaction().add(
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }),
ix
);
const signature = await sendAndConfirmTransaction(rpc, tx, [
payer,
mintSigner,
]);
console.log("Mint:", mintPda.toBase58());
console.log("Tx:", signature);
})();