diff --git a/light-token/cookbook/add-interface-pda.mdx b/light-token/cookbook/add-interface-pda.mdx index 0992af34..9e802bf7 100644 --- a/light-token/cookbook/add-interface-pda.mdx +++ b/light-token/cookbook/add-interface-pda.mdx @@ -6,6 +6,7 @@ description: Create an interface PDA for an existing SPL or Token 2022 mint for import TokenPoolActionCode from "/snippets/code-snippets/light-token/create-token-pool/action.mdx"; import TokenPoolInstructionCode from "/snippets/code-snippets/light-token/create-token-pool/instruction.mdx"; +import TokenPoolTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/create-token-pool/token-interface-instruction.mdx"; import SupportFooter from "/snippets/support-footer.mdx"; import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; import AgentSkillGeneric from "/snippets/setup/agent-skill-generic.mdx"; @@ -32,6 +33,9 @@ import AddInterfacePdaAiPrompt from "/snippets/ai-prompts/ts-cookbook/add-interf + + + diff --git a/light-token/cookbook/approve-revoke.mdx b/light-token/cookbook/approve-revoke.mdx index 466b415b..7ff982eb 100644 --- a/light-token/cookbook/approve-revoke.mdx +++ b/light-token/cookbook/approve-revoke.mdx @@ -22,6 +22,8 @@ import { } from "/snippets/code-samples/code-compare-snippets.jsx"; import TsApproveActionCode from "/snippets/code-snippets/light-token/approve-revoke/approve-action.mdx"; import TsRevokeActionCode from "/snippets/code-snippets/light-token/approve-revoke/revoke-action.mdx"; +import TsApproveTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/approve-revoke/token-interface-approve-instruction.mdx"; +import TsRevokeTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/approve-revoke/token-interface-revoke-instruction.mdx"; import ApproveActionCode from "/snippets/code-snippets/light-token/approve-revoke/rust-client/approve-action.mdx"; import ApproveInstructionCode from "/snippets/code-snippets/light-token/approve-revoke/rust-client/approve-instruction.mdx"; import RevokeActionCode from "/snippets/code-snippets/light-token/approve-revoke/rust-client/revoke-action.mdx"; @@ -103,6 +105,9 @@ import SupportFooter from "/snippets/support-footer.mdx"; + + + @@ -110,6 +115,9 @@ import SupportFooter from "/snippets/support-footer.mdx"; + + + diff --git a/light-token/cookbook/create-ata.mdx b/light-token/cookbook/create-ata.mdx index 831ff425..2787a43f 100644 --- a/light-token/cookbook/create-ata.mdx +++ b/light-token/cookbook/create-ata.mdx @@ -23,6 +23,7 @@ import { } from "/snippets/code-samples/code-compare-snippets.jsx"; import ActionCode from "/snippets/code-snippets/light-token/create-ata/action.mdx"; import InstructionCode from "/snippets/code-snippets/light-token/create-ata/instruction.mdx"; +import TokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/create-ata/token-interface-instruction.mdx"; import RustActionCode from "/snippets/code-snippets/light-token/create-ata/rust-client/action.mdx"; import RustInstructionCode from "/snippets/code-snippets/light-token/create-ata/rust-client/instruction.mdx"; import AnchorProgramCode from "/snippets/code-snippets/light-token/create-ata/anchor-program/full-example.mdx"; @@ -79,6 +80,9 @@ Compare to SPL: + + + diff --git a/light-token/cookbook/create-mint.mdx b/light-token/cookbook/create-mint.mdx index b79f720e..2e4b51af 100644 --- a/light-token/cookbook/create-mint.mdx +++ b/light-token/cookbook/create-mint.mdx @@ -29,10 +29,13 @@ import { } from "/snippets/code-samples/code-compare-snippets.jsx"; import ActionCode from "/snippets/code-snippets/light-token/create-mint/action.mdx"; import InstructionCode from "/snippets/code-snippets/light-token/create-mint/instruction.mdx"; +import TokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/create-mint/token-interface-instruction.mdx"; import SplActionCode from "/snippets/code-snippets/light-token/create-spl-mint/action.mdx"; import SplInstructionCode from "/snippets/code-snippets/light-token/create-spl-mint/instruction.mdx"; +import SplTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/create-spl-mint/token-interface-instruction.mdx"; import T22ActionCode from "/snippets/code-snippets/light-token/create-t22-mint/action.mdx"; import T22InstructionCode from "/snippets/code-snippets/light-token/create-t22-mint/instruction.mdx"; +import T22TokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/create-t22-mint/token-interface-instruction.mdx"; import RustActionCode from "/snippets/code-snippets/light-token/create-mint/rust-client/action.mdx"; import RustInstructionCode from "/snippets/code-snippets/light-token/create-mint/rust-client/instruction.mdx"; @@ -103,6 +106,9 @@ Compare to SPL: + + + @@ -124,6 +130,9 @@ Pass `TOKEN_PROGRAM_ID` to create a standard SPL mint with an interface PDA in o + + + ## Create Token 2022 mint with interface PDA @@ -137,6 +146,9 @@ Pass `TOKEN_2022_PROGRAM_ID` to create a Token-2022 mint with an interface PDA i + + + diff --git a/light-token/cookbook/load-ata.mdx b/light-token/cookbook/load-ata.mdx index 2104091f..e45da727 100644 --- a/light-token/cookbook/load-ata.mdx +++ b/light-token/cookbook/load-ata.mdx @@ -8,6 +8,7 @@ keywords: ["load ata on solana", "get token balance for wallets"] import FullSetup from "/snippets/setup/full-setup.mdx"; import ActionCode from "/snippets/code-snippets/light-token/load-ata/action.mdx"; import InstructionCode from "/snippets/code-snippets/light-token/load-ata/instruction.mdx"; +import TokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/load-ata/token-interface-instruction.mdx"; import AgentSkillGeneric from "/snippets/setup/agent-skill-generic.mdx"; import SupportFooter from "/snippets/support-footer.mdx"; @@ -39,6 +40,9 @@ Find the source code [here](https://github.com/Lightprotocol/light-protocol/blob + + + diff --git a/light-token/cookbook/mint-to.mdx b/light-token/cookbook/mint-to.mdx index c2ba8767..bff1d1fb 100644 --- a/light-token/cookbook/mint-to.mdx +++ b/light-token/cookbook/mint-to.mdx @@ -21,6 +21,7 @@ import { } from "/snippets/code-samples/code-compare-snippets.jsx"; import ActionCode from "/snippets/code-snippets/light-token/mint-to/action.mdx"; import InstructionCode from "/snippets/code-snippets/light-token/mint-to/instruction.mdx"; +import TokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/mint-to/token-interface-instruction.mdx"; import RustActionCode from "/snippets/code-snippets/light-token/mint-to/rust-client/action.mdx"; import RustInstructionCode from "/snippets/code-snippets/light-token/mint-to/rust-client/instruction.mdx"; import AnchorProgramCode from "/snippets/code-snippets/light-token/mint-to/anchor-program/full-example.mdx"; @@ -73,6 +74,9 @@ Compare to SPL: + + + diff --git a/light-token/cookbook/transfer-delegated.mdx b/light-token/cookbook/transfer-delegated.mdx index 636a9da5..1a37ef76 100644 --- a/light-token/cookbook/transfer-delegated.mdx +++ b/light-token/cookbook/transfer-delegated.mdx @@ -9,6 +9,7 @@ import FullSetup from "/snippets/setup/full-setup.mdx"; import AgentSkillGeneric from "/snippets/setup/agent-skill-generic.mdx"; import DelegateTransferAction from "/snippets/code-snippets/payments/spend-permissions/delegate-transfer.mdx"; import DelegateTransferInstruction from "/snippets/code-snippets/payments/spend-permissions/delegate-transfer-instruction.mdx"; +import DelegateTransferTokenInterfaceInstruction from "/snippets/code-snippets/payments/spend-permissions/delegate-transfer-token-interface-instruction.mdx"; import SupportFooter from "/snippets/support-footer.mdx"; `transferInterface` with `{ owner }` transfers tokens from an associated token account as an approved delegate. The delegate is the transaction authority. Only the delegate and fee payer sign; the owner's signature is not required. @@ -35,6 +36,9 @@ import SupportFooter from "/snippets/support-footer.mdx"; + + + diff --git a/light-token/cookbook/transfer-interface.mdx b/light-token/cookbook/transfer-interface.mdx index 885f1417..09983982 100644 --- a/light-token/cookbook/transfer-interface.mdx +++ b/light-token/cookbook/transfer-interface.mdx @@ -18,6 +18,7 @@ import { } from "/snippets/code-samples/code-compare-snippets.jsx"; import ActionCode from "/snippets/code-snippets/light-token/transfer-interface/action.mdx"; import InstructionCode from "/snippets/code-snippets/light-token/transfer-interface/instruction.mdx"; +import TokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/transfer-interface/token-interface-instruction.mdx"; import RustActionCode from "/snippets/code-snippets/light-token/transfer-interface/rust-client/action.mdx"; import RustInstructionCode from "/snippets/code-snippets/light-token/transfer-interface/rust-client/instruction.mdx"; import AnchorProgramCode from "/snippets/code-snippets/light-token/transfer-interface/anchor-program/full-example.mdx"; @@ -99,6 +100,9 @@ Compare to SPL: + + + @@ -160,6 +164,43 @@ const batches = await createTransferToAccountInterfaceInstructions( const { rest: loads, last: transfer } = sliceLast(batches); ``` + + + +```typescript +import { Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { + createTransferCheckedInstruction, + createLoadInstructions, +} from "@lightprotocol/token-interface"; + +// The destination must be an existing token account. +const destinationTokenAccount = /* existing ATA or program-owned token account */; +const sourceAta = /* owner's Light ATA */; +const decimals = 9; + +const loadIxs = await createLoadInstructions({ + rpc, + payer: payer.publicKey, + owner: owner.publicKey, + mint, + authority: owner.publicKey, +}); + +const transferIx = createTransferCheckedInstruction({ + source: sourceAta, + destination: destinationTokenAccount, + mint, + authority: owner.publicKey, + payer: payer.publicKey, + amount: 500_000_000n, + decimals, +}); + +const tx = new Transaction().add(...loadIxs, transferIx); +await sendAndConfirmTransaction(rpc, tx, [payer, owner]); +``` + diff --git a/light-token/cookbook/wrap-unwrap.mdx b/light-token/cookbook/wrap-unwrap.mdx index def603e2..574a8d1c 100644 --- a/light-token/cookbook/wrap-unwrap.mdx +++ b/light-token/cookbook/wrap-unwrap.mdx @@ -10,8 +10,10 @@ keywords: ["wrap tokens on solana", "unwrap tokens for developers", "spl to ligh import FullSetup from "/snippets/setup/full-setup.mdx"; import WrapActionCode from "/snippets/code-snippets/light-token/wrap/action.mdx"; import WrapInstructionCode from "/snippets/code-snippets/light-token/wrap/instruction.mdx"; +import WrapTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/wrap/token-interface-instruction.mdx"; import UnwrapActionCode from "/snippets/code-snippets/light-token/unwrap/action.mdx"; import UnwrapInstructionCode from "/snippets/code-snippets/light-token/unwrap/instruction.mdx"; +import UnwrapTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/unwrap/token-interface-instruction.mdx"; import WrapRustActionCode from "/snippets/code-snippets/light-token/wrap/rust-client/action.mdx"; import UnwrapRustActionCode from "/snippets/code-snippets/light-token/unwrap/rust-client/action.mdx"; import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; @@ -53,6 +55,9 @@ import SupportFooter from "/snippets/support-footer.mdx"; + + + @@ -73,6 +78,9 @@ import SupportFooter from "/snippets/support-footer.mdx"; + + + diff --git a/light-token/payments/basic-payment.mdx b/light-token/payments/basic-payment.mdx index 8fd7fc51..dc05e532 100644 --- a/light-token/payments/basic-payment.mdx +++ b/light-token/payments/basic-payment.mdx @@ -10,8 +10,10 @@ import SupportFooter from "/snippets/support-footer.mdx"; import AgentSkillPayments from "/snippets/setup/agent-skill-payments.mdx"; import PaymentsAiPrompt from "/snippets/ai-prompts/toolkits/payments.mdx"; import PaymentsSetupHelper from "/snippets/setup/payments-setup-helper.mdx"; +import TokenInterfaceSdk2Callout from "/snippets/light-token-guides/token-interface-sdk2-callout.mdx"; import SendInstructionCode from "/snippets/code-snippets/payments/send/basic-send-instruction.mdx"; import SendActionCode from "/snippets/code-snippets/payments/send/basic-send-action.mdx"; +import SendTokenInterfaceInstructionCode from "/snippets/code-snippets/payments/send/basic-send-token-interface-instruction.mdx"; 1. The light-token API matches the SPL-token API almost entirely, and extends their functionality to include the light token program in addition to the SPL-token and Token-2022 programs. 2. Your users use the same stablecoins, just stored more efficiently. @@ -81,6 +83,7 @@ instructions to load them. This almost always fits in a single atomic transaction with your regular transfer. APIs return `TransactionInstruction[][]` so the same loop handles the rare multi-transaction case automatically. + @@ -165,6 +168,11 @@ await sendAndConfirmTransaction(rpc, transferTx); + + + + + diff --git a/light-token/payments/batch-payments.mdx b/light-token/payments/batch-payments.mdx index 970c9b28..a04965c4 100644 --- a/light-token/payments/batch-payments.mdx +++ b/light-token/payments/batch-payments.mdx @@ -10,6 +10,7 @@ import SupportFooter from "/snippets/support-footer.mdx"; import AgentSkillPayments from "/snippets/setup/agent-skill-payments.mdx"; import PaymentsAiPrompt from "/snippets/ai-prompts/toolkits/payments.mdx"; import PaymentsSetupHelper from "/snippets/setup/payments-setup-helper.mdx"; +import TokenInterfaceSdk2Callout from "/snippets/light-token-guides/token-interface-sdk2-callout.mdx"; import BatchSendCode from "/snippets/code-snippets/payments/send/batch-send.mdx"; import SplBatchSend from "/snippets/code-snippets/payments/spl/batch-send.mdx"; @@ -76,6 +77,7 @@ atomic transaction with your regular transfer. APIs return `TransactionInstructi so the same loop handles the rare multi-transaction case automatically. + diff --git a/light-token/payments/payment-with-memo.mdx b/light-token/payments/payment-with-memo.mdx index abb51831..2294842a 100644 --- a/light-token/payments/payment-with-memo.mdx +++ b/light-token/payments/payment-with-memo.mdx @@ -10,6 +10,7 @@ import SupportFooter from "/snippets/support-footer.mdx"; import AgentSkillPayments from "/snippets/setup/agent-skill-payments.mdx"; import PaymentsAiPrompt from "/snippets/ai-prompts/toolkits/payments.mdx"; import PaymentsSetupHelper from "/snippets/setup/payments-setup-helper.mdx"; +import TokenInterfaceSdk2Callout from "/snippets/light-token-guides/token-interface-sdk2-callout.mdx"; import MemoCode from "/snippets/code-snippets/payments/send/payment-with-memo.mdx"; import SplMemo from "/snippets/code-snippets/payments/spl/payment-with-memo.mdx"; @@ -80,6 +81,7 @@ atomic transaction with your regular transfer. APIs return `TransactionInstructi so the same loop handles the rare multi-transaction case automatically. + diff --git a/light-token/payments/wrap-unwrap.mdx b/light-token/payments/wrap-unwrap.mdx index 28f5e756..f60aed6e 100644 --- a/light-token/payments/wrap-unwrap.mdx +++ b/light-token/payments/wrap-unwrap.mdx @@ -7,6 +7,8 @@ keywords: ["wrap tokens solana", "unwrap tokens solana", "spl to light token", " import RegisterSplMint from "/snippets/setup/register-spl-mint.mdx"; import FullSetup from "/snippets/setup/full-setup.mdx"; +import WrapTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/wrap/token-interface-instruction.mdx"; +import UnwrapTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/unwrap/token-interface-instruction.mdx"; import SupportFooter from "/snippets/support-footer.mdx"; import AgentSkillPayments from "/snippets/setup/agent-skill-payments.mdx"; import PaymentsAiPrompt from "/snippets/ai-prompts/toolkits/payments.mdx"; @@ -64,6 +66,11 @@ const tx = new Transaction().add( ); ``` + + + + + @@ -118,6 +125,11 @@ for (const ixs of instructions) { } ``` + + + + + diff --git a/light-token/wallets/overview.mdx b/light-token/wallets/overview.mdx index 37dcc502..64476f70 100644 --- a/light-token/wallets/overview.mdx +++ b/light-token/wallets/overview.mdx @@ -7,7 +7,12 @@ keywords: ["wallet infrastructure on solana", "scalable wallet infrastructure on import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; import ToolkitsSetup from "/snippets/setup/toolkits-setup.mdx"; +import LoadAtaTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/load-ata/token-interface-instruction.mdx"; +import SendTokenInterfaceInstructionCode from "/snippets/code-snippets/payments/send/basic-send-token-interface-instruction.mdx"; +import WrapTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/wrap/token-interface-instruction.mdx"; +import UnwrapTokenInterfaceInstructionCode from "/snippets/code-snippets/light-token/unwrap/token-interface-instruction.mdx"; import AgentSkillPayments from "/snippets/setup/agent-skill-payments.mdx"; +import TokenInterfaceSdk2Callout from "/snippets/light-token-guides/token-interface-sdk2-callout.mdx"; import WalletsAiPrompt from "/snippets/ai-prompts/toolkits/wallets.mdx"; import SupportFooter from "/snippets/support-footer.mdx"; import TokenAccountCost from "/snippets/cost-tables/token-account-cost.mdx"; @@ -103,6 +108,7 @@ instructions to load them. This almost always fits in a single atomic transaction with your regular transfer. APIs return `TransactionInstruction[][]` so the same loop handles the rare multi-transaction case automatically. + ## Receive Payments @@ -141,6 +147,11 @@ for (const ixs of instructions) { } ``` + + + + + @@ -236,6 +247,11 @@ const tx = new Transaction().add( + + + + + @@ -375,6 +391,11 @@ const tx = new Transaction().add( ); ``` + + + + + @@ -429,6 +450,11 @@ for (const ixs of instructions) { } ``` + + + + + diff --git a/snippets/code-snippets/light-token/approve-revoke/token-interface-approve-instruction.mdx b/snippets/code-snippets/light-token/approve-revoke/token-interface-approve-instruction.mdx new file mode 100644 index 00000000..fd30329f --- /dev/null +++ b/snippets/code-snippets/light-token/approve-revoke/token-interface-approve-instruction.mdx @@ -0,0 +1,29 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc } from "@lightprotocol/stateless.js"; +import { createApproveInstructions } from "@lightprotocol/token-interface"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); + +const mint = /* existing mint public key */; +const owner = Keypair.generate(); +const delegate = Keypair.generate(); + +const instructions = await createApproveInstructions({ + rpc, + payer: payer.publicKey, + owner: owner.publicKey, + mint, + delegate: delegate.publicKey, + amount: 500_000_000n, +}); + +const signature = await sendAndConfirmTransaction( + rpc, + new Transaction().add(...instructions), + [payer, owner] +); +console.log("Approved delegate:", delegate.publicKey.toBase58()); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/light-token/approve-revoke/token-interface-revoke-instruction.mdx b/snippets/code-snippets/light-token/approve-revoke/token-interface-revoke-instruction.mdx new file mode 100644 index 00000000..f925e8a8 --- /dev/null +++ b/snippets/code-snippets/light-token/approve-revoke/token-interface-revoke-instruction.mdx @@ -0,0 +1,26 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc } from "@lightprotocol/stateless.js"; +import { createRevokeInstructions } from "@lightprotocol/token-interface"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); + +const mint = /* existing mint public key */; +const owner = Keypair.generate(); + +const instructions = await createRevokeInstructions({ + rpc, + payer: payer.publicKey, + owner: owner.publicKey, + mint, +}); + +const signature = await sendAndConfirmTransaction( + rpc, + new Transaction().add(...instructions), + [payer, owner] +); +console.log("Revoked all delegate permissions"); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/light-token/create-ata/token-interface-instruction.mdx b/snippets/code-snippets/light-token/create-ata/token-interface-instruction.mdx new file mode 100644 index 00000000..9dce2f72 --- /dev/null +++ b/snippets/code-snippets/light-token/create-ata/token-interface-instruction.mdx @@ -0,0 +1,24 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc, LIGHT_TOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; +import { createAtaInstruction, getAtaAddress } from "@lightprotocol/token-interface"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); + +const mint = /* existing mint public key */; +const owner = Keypair.generate(); +const associatedToken = getAtaAddress({ mint, owner: owner.publicKey }); + +const ix = createAtaInstruction({ + payer: payer.publicKey, + owner: owner.publicKey, + mint, + programId: LIGHT_TOKEN_PROGRAM_ID, +}); + +const tx = new Transaction().add(ix); +const signature = await sendAndConfirmTransaction(rpc, tx, [payer]); +console.log("ATA:", associatedToken.toBase58()); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/light-token/create-mint/token-interface-instruction.mdx b/snippets/code-snippets/light-token/create-mint/token-interface-instruction.mdx new file mode 100644 index 00000000..0b9324ae --- /dev/null +++ b/snippets/code-snippets/light-token/create-mint/token-interface-instruction.mdx @@ -0,0 +1,38 @@ +```typescript +import { Buffer } from "buffer"; +import { + Keypair, + PublicKey, + Transaction, + sendAndConfirmTransaction, +} from "@solana/web3.js"; +import { createRpc, LIGHT_TOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; +import { createMintInstructions } from "@lightprotocol/token-interface"; + +const COMPRESSED_MINT_SEED = Buffer.from("compressed_mint"); +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); + +function findMintAddress(mintSigner: PublicKey): [PublicKey, number] { + return PublicKey.findProgramAddressSync( + [COMPRESSED_MINT_SEED, mintSigner.toBuffer()], + LIGHT_TOKEN_PROGRAM_ID + ); +} + +const mintSigner = Keypair.generate(); +const [mintPda] = findMintAddress(mintSigner.publicKey); +const instructions = await createMintInstructions({ + rpc, + payer: payer.publicKey, + keypair: mintSigner, + decimals: 9, + mintAuthority: payer.publicKey, + tokenProgramId: LIGHT_TOKEN_PROGRAM_ID, +}); + +const tx = new Transaction().add(...instructions); +const signature = await sendAndConfirmTransaction(rpc, tx, [payer, mintSigner]); +console.log("Mint:", mintPda.toBase58()); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/light-token/create-spl-mint/token-interface-instruction.mdx b/snippets/code-snippets/light-token/create-spl-mint/token-interface-instruction.mdx new file mode 100644 index 00000000..852ead36 --- /dev/null +++ b/snippets/code-snippets/light-token/create-spl-mint/token-interface-instruction.mdx @@ -0,0 +1,24 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc } from "@lightprotocol/stateless.js"; +import { createMintInstructions } from "@lightprotocol/token-interface"; +import { TOKEN_PROGRAM_ID } from "@solana/spl-token"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); +const mintKeypair = Keypair.generate(); + +const instructions = await createMintInstructions({ + rpc, + payer: payer.publicKey, + keypair: mintKeypair, + decimals: 9, + mintAuthority: payer.publicKey, + tokenProgramId: TOKEN_PROGRAM_ID, +}); + +const tx = new Transaction().add(...instructions); +const signature = await sendAndConfirmTransaction(rpc, tx, [payer, mintKeypair]); +console.log("Mint:", mintKeypair.publicKey.toBase58()); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/light-token/create-t22-mint/token-interface-instruction.mdx b/snippets/code-snippets/light-token/create-t22-mint/token-interface-instruction.mdx new file mode 100644 index 00000000..381928aa --- /dev/null +++ b/snippets/code-snippets/light-token/create-t22-mint/token-interface-instruction.mdx @@ -0,0 +1,24 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc } from "@lightprotocol/stateless.js"; +import { createMintInstructions } from "@lightprotocol/token-interface"; +import { TOKEN_2022_PROGRAM_ID } from "@solana/spl-token"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); +const mintKeypair = Keypair.generate(); + +const instructions = await createMintInstructions({ + rpc, + payer: payer.publicKey, + keypair: mintKeypair, + decimals: 9, + mintAuthority: payer.publicKey, + tokenProgramId: TOKEN_2022_PROGRAM_ID, +}); + +const tx = new Transaction().add(...instructions); +const signature = await sendAndConfirmTransaction(rpc, tx, [payer, mintKeypair]); +console.log("Mint:", mintKeypair.publicKey.toBase58()); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/light-token/create-token-pool/token-interface-instruction.mdx b/snippets/code-snippets/light-token/create-token-pool/token-interface-instruction.mdx new file mode 100644 index 00000000..e1f9aa24 --- /dev/null +++ b/snippets/code-snippets/light-token/create-token-pool/token-interface-instruction.mdx @@ -0,0 +1,22 @@ +```typescript +import { Keypair, PublicKey, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc } from "@lightprotocol/stateless.js"; +import { createSplInterfaceInstruction } from "@lightprotocol/token-interface"; +import { TOKEN_PROGRAM_ID } from "@solana/spl-token"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); +const existingMint = new PublicKey("YOUR_EXISTING_MINT_ADDRESS"); + +const ix = createSplInterfaceInstruction({ + feePayer: payer.publicKey, + mint: existingMint, + index: 0, + tokenProgramId: TOKEN_PROGRAM_ID, +}); + +const tx = new Transaction().add(ix); +const signature = await sendAndConfirmTransaction(rpc, tx, [payer]); +console.log("Mint:", existingMint.toBase58()); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/light-token/load-ata/token-interface-instruction.mdx b/snippets/code-snippets/light-token/load-ata/token-interface-instruction.mdx new file mode 100644 index 00000000..1bbebc84 --- /dev/null +++ b/snippets/code-snippets/light-token/load-ata/token-interface-instruction.mdx @@ -0,0 +1,25 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc } from "@lightprotocol/stateless.js"; +import { createLoadInstructions } from "@lightprotocol/token-interface"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); + +const mint = /* existing mint public key */; +const owner = payer.publicKey; + +const instructions = await createLoadInstructions({ + rpc, + payer: payer.publicKey, + owner, + mint, + authority: owner, +}); + +if (instructions.length > 0) { + const tx = new Transaction().add(...instructions); + const signature = await sendAndConfirmTransaction(rpc, tx, [payer]); + console.log("Tx:", signature); +} +``` diff --git a/snippets/code-snippets/light-token/mint-to/token-interface-instruction.mdx b/snippets/code-snippets/light-token/mint-to/token-interface-instruction.mdx new file mode 100644 index 00000000..3bf301d3 --- /dev/null +++ b/snippets/code-snippets/light-token/mint-to/token-interface-instruction.mdx @@ -0,0 +1,36 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc, LIGHT_TOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; +import { + createAtaInstruction, + createMintToInstruction, + getAtaAddress, +} from "@lightprotocol/token-interface"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); + +const mint = /* existing mint public key */; +const recipient = Keypair.generate(); +const destination = getAtaAddress({ mint, owner: recipient.publicKey }); + +const createAtaIx = createAtaInstruction({ + payer: payer.publicKey, + owner: recipient.publicKey, + mint, + programId: LIGHT_TOKEN_PROGRAM_ID, +}); + +const mintToIx = createMintToInstruction({ + mint, + destination, + authority: payer.publicKey, + payer: payer.publicKey, + amount: 1_000_000_000n, + tokenProgramId: LIGHT_TOKEN_PROGRAM_ID, +}); + +const tx = new Transaction().add(createAtaIx, mintToIx); +const signature = await sendAndConfirmTransaction(rpc, tx, [payer]); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/light-token/transfer-interface/token-interface-instruction.mdx b/snippets/code-snippets/light-token/transfer-interface/token-interface-instruction.mdx new file mode 100644 index 00000000..aac4622e --- /dev/null +++ b/snippets/code-snippets/light-token/transfer-interface/token-interface-instruction.mdx @@ -0,0 +1,30 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc } from "@lightprotocol/stateless.js"; +import { createTransferInstructions } from "@lightprotocol/token-interface"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); + +const mint = /* existing mint public key */; +const sourceOwner = Keypair.generate(); +const authority = sourceOwner; // delegate Keypair for delegated transfer +const recipient = Keypair.generate(); + +const transferIxs = await createTransferInstructions({ + rpc, + payer: payer.publicKey, + mint, + sourceOwner: sourceOwner.publicKey, + authority: authority.publicKey, + recipient: recipient.publicKey, + amount: 500_000_000n, +}); + +const signature = await sendAndConfirmTransaction( + rpc, + new Transaction().add(...transferIxs), + [payer, authority] +); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/light-token/unwrap/token-interface-instruction.mdx b/snippets/code-snippets/light-token/unwrap/token-interface-instruction.mdx new file mode 100644 index 00000000..5f0d14d0 --- /dev/null +++ b/snippets/code-snippets/light-token/unwrap/token-interface-instruction.mdx @@ -0,0 +1,32 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc } from "@lightprotocol/stateless.js"; +import { createUnwrapInstruction, getSplInterfaces } from "@lightprotocol/token-interface"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); + +const mint = /* existing SPL/Token-2022 mint */; +const lightTokenAta = /* existing Light ATA */; +const splAta = /* destination SPL ATA */; + +const splInterfaces = await getSplInterfaces(rpc, mint); +const splInterface = + splInterfaces.find((info) => info.isInitialized) ?? splInterfaces[0]; +if (!splInterface) throw new Error("No SPL interface found"); + +const unwrapIx = createUnwrapInstruction({ + source: lightTokenAta, + destination: splAta, + owner: payer.publicKey, + mint, + amount: 500n, + splInterface, + decimals: 9, + payer: payer.publicKey, +}); + +const tx = new Transaction().add(unwrapIx); +const signature = await sendAndConfirmTransaction(rpc, tx, [payer]); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/light-token/wrap/token-interface-instruction.mdx b/snippets/code-snippets/light-token/wrap/token-interface-instruction.mdx new file mode 100644 index 00000000..20af94b8 --- /dev/null +++ b/snippets/code-snippets/light-token/wrap/token-interface-instruction.mdx @@ -0,0 +1,47 @@ +```typescript +import { ComputeBudgetProgram, Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createRpc } from "@lightprotocol/stateless.js"; +import { + createAtaInstruction, + createWrapInstruction, + getAtaAddress, + getSplInterfaces, +} from "@lightprotocol/token-interface"; + +const rpc = createRpc(); +const payer = Keypair.fromSecretKey(/* ... */); + +const mint = /* existing SPL/Token-2022 mint */; +const splAta = /* existing SPL ATA */; +const lightTokenAta = getAtaAddress({ mint, owner: payer.publicKey }); + +const createAtaIx = createAtaInstruction({ + payer: payer.publicKey, + owner: payer.publicKey, + mint, +}); + +const splInterfaces = await getSplInterfaces(rpc, mint); +const splInterface = + splInterfaces.find((info) => info.isInitialized) ?? splInterfaces[0]; +if (!splInterface) throw new Error("No SPL interface found"); + +const wrapIx = createWrapInstruction({ + source: splAta, + destination: lightTokenAta, + owner: payer.publicKey, + mint, + amount: 500n, + splInterface, + decimals: 9, + payer: payer.publicKey, +}); + +const tx = new Transaction().add( + ComputeBudgetProgram.setComputeUnitLimit({ units: 200_000 }), + createAtaIx, + wrapIx +); +const signature = await sendAndConfirmTransaction(rpc, tx, [payer]); +console.log("Tx:", signature); +``` diff --git a/snippets/code-snippets/payments/send/basic-send-token-interface-instruction.mdx b/snippets/code-snippets/payments/send/basic-send-token-interface-instruction.mdx new file mode 100644 index 00000000..a4f2e588 --- /dev/null +++ b/snippets/code-snippets/payments/send/basic-send-token-interface-instruction.mdx @@ -0,0 +1,24 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { createTransferInstructions } from "@lightprotocol/token-interface"; +import { rpc, payer, setup } from "../setup.js"; + +(async function () { + const { mint } = await setup(); + const recipient = Keypair.generate(); + + const instructions = await createTransferInstructions({ + rpc, + payer: payer.publicKey, + mint, + sourceOwner: payer.publicKey, + authority: payer.publicKey, + recipient: recipient.publicKey, + amount: 100n, + }); + + const tx = new Transaction().add(...instructions); + const sig = await sendAndConfirmTransaction(rpc, tx, [payer]); + console.log("Tx:", sig); +})(); +``` diff --git a/snippets/code-snippets/payments/spend-permissions/delegate-transfer-token-interface-instruction.mdx b/snippets/code-snippets/payments/spend-permissions/delegate-transfer-token-interface-instruction.mdx new file mode 100644 index 00000000..69a81f63 --- /dev/null +++ b/snippets/code-snippets/payments/spend-permissions/delegate-transfer-token-interface-instruction.mdx @@ -0,0 +1,40 @@ +```typescript +import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; +import { + createApproveInstructions, + createTransferInstructions, +} from "@lightprotocol/token-interface"; +import { rpc, payer, setup } from "../setup.js"; + +(async function () { + const { mint } = await setup(); + const delegate = Keypair.generate(); + const recipient = Keypair.generate(); + + const approveIxs = await createApproveInstructions({ + rpc, + payer: payer.publicKey, + owner: payer.publicKey, + mint, + delegate: delegate.publicKey, + amount: 500_000_000n, + }); + await sendAndConfirmTransaction(rpc, new Transaction().add(...approveIxs), [payer]); + + const transferIxs = await createTransferInstructions({ + rpc, + payer: payer.publicKey, + mint, + sourceOwner: payer.publicKey, + authority: delegate.publicKey, + recipient: recipient.publicKey, + amount: 200_000_000n, + }); + const sig = await sendAndConfirmTransaction( + rpc, + new Transaction().add(...transferIxs), + [payer, delegate] + ); + console.log("Tx:", sig); +})(); +``` diff --git a/snippets/light-token-guides/token-interface-sdk2-callout.mdx b/snippets/light-token-guides/token-interface-sdk2-callout.mdx new file mode 100644 index 00000000..34c33f10 --- /dev/null +++ b/snippets/light-token-guides/token-interface-sdk2-callout.mdx @@ -0,0 +1,5 @@ + + **SDK 2.0 (`@lightprotocol/token-interface`)** is the latest JavaScript SDK. + It has better API ergonomics, guarantees single-instruction loading, and is + compatible with KIT (the new Solana SDKs). + diff --git a/snippets/setup/full-setup.mdx b/snippets/setup/full-setup.mdx index 71782436..c5ad969a 100644 --- a/snippets/setup/full-setup.mdx +++ b/snippets/setup/full-setup.mdx @@ -38,6 +38,27 @@ Install the CLI globally: pnpm add -g @lightprotocol/zk-compression-cli ``` + + + Install packages in your working directory: + ```bash + # npm + npm install @lightprotocol/stateless.js@^0.23.0 \ + @lightprotocol/token-interface@^0.1.2 + + # yarn + yarn add @lightprotocol/stateless.js@^0.23.0 \ + @lightprotocol/token-interface@^0.1.2 + + # pnpm + pnpm add @lightprotocol/stateless.js@^0.23.0 \ + @lightprotocol/token-interface@^0.1.2 + ``` +Install the CLI globally: + ```bash + npm install -g @lightprotocol/zk-compression-cli + ``` + diff --git a/snippets/setup/toolkits-setup.mdx b/snippets/setup/toolkits-setup.mdx index f8bba7d0..b271bc3e 100644 --- a/snippets/setup/toolkits-setup.mdx +++ b/snippets/setup/toolkits-setup.mdx @@ -1,4 +1,14 @@ + + ```bash npm install @lightprotocol/compressed-token@^0.23.0 \ @lightprotocol/stateless.js@^0.23.0 ``` + + +```bash +npm install @lightprotocol/token-interface@^0.1.2 \ + @lightprotocol/stateless.js@^0.23.0 +``` + + diff --git a/snippets/setup/welcome-page-install.mdx b/snippets/setup/welcome-page-install.mdx index 61f27ae8..4126c867 100644 --- a/snippets/setup/welcome-page-install.mdx +++ b/snippets/setup/welcome-page-install.mdx @@ -36,4 +36,24 @@ Install the CLI globally: pnpm add -g @lightprotocol/zk-compression-cli ``` + + Install packages in your working directory: + ```bash + # npm + npm install @lightprotocol/stateless.js@^0.23.0 \ + @lightprotocol/token-interface@^0.1.2 + + # yarn + yarn add @lightprotocol/stateless.js@^0.23.0 \ + @lightprotocol/token-interface@^0.1.2 + + # pnpm + pnpm add @lightprotocol/stateless.js@^0.23.0 \ + @lightprotocol/token-interface@^0.1.2 + ``` +Install the CLI globally: + ```bash + npm install -g @lightprotocol/zk-compression-cli + ``` + diff --git a/snippets/versions/sdk-install-0.23.0.mdx b/snippets/versions/sdk-install-0.23.0.mdx index 3aa34f43..5efc9e34 100644 --- a/snippets/versions/sdk-install-0.23.0.mdx +++ b/snippets/versions/sdk-install-0.23.0.mdx @@ -17,4 +17,19 @@ @lightprotocol/compressed-token@^0.23.0 ``` + + ```bash + # npm + npm install @lightprotocol/stateless.js@^0.23.0 \ + @lightprotocol/token-interface@^0.1.2 + + # yarn + yarn add @lightprotocol/stateless.js@^0.23.0 \ + @lightprotocol/token-interface@^0.1.2 + + # pnpm + pnpm add @lightprotocol/stateless.js@^0.23.0 \ + @lightprotocol/token-interface@^0.1.2 + ``` +