Skip to content

Commit b9c7b24

Browse files
add compress with delegate example (#14)
1 parent 1302a00 commit b9c7b24

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"connection": "ts-node src/scripts/connection.ts",
1111
"lookup-table": "ts-node src/scripts/lookup-table.ts",
1212
"batch-compress": "ts-node src/scripts/batch-compress.ts",
13+
"compress-with-delegate": "ts-node src/scripts/compress-with-delegate.ts",
1314
"mint-spl": "ts-node src/scripts/mint-spl.ts",
1415
"mint-spl-22": "ts-node src/scripts/mint-spl-22.ts",
1516
"mint-spl-22-manual": "ts-node src/scripts/mint-spl-22-manual.ts",

src/scripts/compress-with-delegate.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Rpc, confirmTx, createRpc } from "@lightprotocol/stateless.js";
2+
import { compress, createMint } from "@lightprotocol/compressed-token";
3+
import {
4+
getOrCreateAssociatedTokenAccount,
5+
mintTo as mintToSpl,
6+
approve,
7+
} from "@solana/spl-token";
8+
import { PAYER_KEYPAIR, RPC_ENDPOINT } from "../constants";
9+
import { Keypair } from "@solana/web3.js";
10+
11+
const payer = PAYER_KEYPAIR;
12+
const delegate = Keypair.generate();
13+
const recipient = Keypair.generate();
14+
console.log(`delegate: ${delegate.publicKey.toBase58()}`);
15+
console.log(`recipient: ${recipient.publicKey.toBase58()}`);
16+
17+
// Ensure you have light test-validator running
18+
const connection: Rpc = createRpc();
19+
20+
(async () => {
21+
/// airdrop lamports to pay fees
22+
await confirmTx(
23+
connection,
24+
await connection.requestAirdrop(payer.publicKey, 1e7)
25+
);
26+
27+
const { mint, transactionSignature } = await createMint(
28+
connection,
29+
payer,
30+
payer.publicKey,
31+
9
32+
);
33+
console.log(`create-mint success! txId: ${transactionSignature}`);
34+
35+
// Get ATA
36+
const ata = await getOrCreateAssociatedTokenAccount(
37+
connection,
38+
payer,
39+
mint,
40+
payer.publicKey
41+
);
42+
43+
/// Mint SPL
44+
const mintTxId = await mintToSpl(
45+
connection,
46+
payer,
47+
mint,
48+
ata.address,
49+
payer.publicKey,
50+
1e5
51+
);
52+
console.log(`mint success! txId: ${mintTxId}`);
53+
54+
const approveTxId = await approve(
55+
connection,
56+
payer,
57+
ata.address,
58+
delegate.publicKey,
59+
payer.publicKey,
60+
1e5
61+
);
62+
console.log(`approve success! txId: ${approveTxId}`);
63+
64+
const compressTxId = await compress(
65+
connection,
66+
payer,
67+
mint,
68+
1e5,
69+
delegate,
70+
ata.address,
71+
recipient.publicKey
72+
);
73+
console.log(`compress success! txId: ${compressTxId}`);
74+
})();

0 commit comments

Comments
 (0)