11import "dotenv/config" ;
22import { Keypair } from "@solana/web3.js" ;
33import { createRpc , bn } from "@lightprotocol/stateless.js" ;
4- import {
5- createMint ,
6- mintTo ,
7- decompress ,
8- compress ,
9- } from "@lightprotocol/compressed-token" ;
4+ import { createMint , mintTo , decompress , compress } from "@lightprotocol/compressed-token" ;
105import { createAssociatedTokenAccount } from "@solana/spl-token" ;
116import { homedir } from "os" ;
127import { readFileSync } from "fs" ;
@@ -18,42 +13,20 @@ const payer = Keypair.fromSecretKey(
1813 )
1914) ;
2015
21- async function main ( ) {
16+ ( async function ( ) {
2217 const rpc = createRpc ( RPC_URL ) ;
2318
19+ // Setup: Get SPL tokens (needed to compress)
2420 const { mint } = await createMint ( rpc , payer , payer . publicKey , 9 ) ;
25- console . log ( "Mint:" , mint . toBase58 ( ) ) ;
26-
27- const splAta = await createAssociatedTokenAccount (
28- rpc ,
29- payer ,
30- mint ,
31- payer . publicKey
32- ) ;
33-
34- // Fund SPL ATA: mint compressed, then decompress
21+ const splAta = await createAssociatedTokenAccount ( rpc , payer , mint , payer . publicKey ) ;
3522 await mintTo ( rpc , payer , mint , payer . publicKey , payer , bn ( 10000 ) ) ;
3623 await decompress ( rpc , payer , mint , bn ( 10000 ) , payer , splAta ) ;
3724
3825 // Batch compress to multiple recipients
39- const recipients = Array . from (
40- { length : 5 } ,
41- ( ) => Keypair . generate ( ) . publicKey
42- ) ;
26+ const recipients = Array . from ( { length : 5 } , ( ) => Keypair . generate ( ) . publicKey ) ;
4327 const amounts = [ bn ( 100 ) , bn ( 200 ) , bn ( 300 ) , bn ( 400 ) , bn ( 500 ) ] ;
4428
45- const signature = await compress (
46- rpc ,
47- payer ,
48- mint ,
49- amounts ,
50- payer ,
51- splAta ,
52- recipients
53- ) ;
54-
55- console . log ( "Batch compressed to 5 recipients" ) ;
56- console . log ( "Tx:" , signature ) ;
57- }
29+ const tx = await compress ( rpc , payer , mint , amounts , payer , splAta , recipients ) ;
5830
59- main ( ) . catch ( console . error ) ;
31+ console . log ( "Tx:" , tx ) ;
32+ } ) ( ) ;
0 commit comments