|
| 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