### Install Account Compression SDK Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/account-compression/usage.md Demonstrates how to install the @solana/spl-account-compression and @solana/web3.js libraries using npm or yarn. ```shell npm install --save @solana/spl-account-compression @solana/web3.js@1 ``` ```shell yarn add @solana/spl-account-compression @solana/web3.js@1 ``` -------------------------------- ### Start Solana Test Validator with Account Directory (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/wallet.md This command starts a local Solana test validator and loads accounts from a specified directory. This is useful for quickly setting up a testing environment with pre-configured accounts. Requires the solana-test-validator executable. ```console $ solana-test-validator -r --account-dir test-accounts ``` -------------------------------- ### Execute Stake Pool Setup Script Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/stake-pool/quickstart.md This bash script sets up a local test validator with a specified number of validator vote accounts. It outputs the base58-encoded public keys of these accounts to a file. Ensure no other solana-test-validator is running. ```bash #!/bin/bash # Example usage: # ./setup-test-validator.sh 10 local_validators.txt NUM_VOTE_ACCOUNTS=$1 OUTPUT_FILE=$2 solana-test-validator \ --reset \ --cuk 1000 \ --faucet-url http://localhost:8899 \ --bpf-program StakePool "$(solana program show stake-pool --output json | jq -r .programid)" \ --programs-dir target/deploy \ --slots-per-epoch 32 \ --stakes & VAL_PID=$! sleep 5 for i in $(seq 1 $NUM_VOTE_ACCOUNTS); do solana-keygen new --no-passphrase -f so \ --outfile "./stake-pool-keys/validator-$i.json" solana stake-account \ --fromStakePool $(cat ./stake-pool-keys/validator-$i.json | jq -r .publicKey) \ --stakePool "$(solana program show stake-pool --output json | jq -r .programid)" \ --commission 10 \ --vote-account "$(solana-keygen new --no-passphrase -f so | jq -r .publicKey)" \ --stake-authority $(cat ./stake-pool-keys/validator-$i.json | jq -r .publicKey) \ --withdraw-authority $(cat ./stake-pool-keys/validator-$i.json | jq -r .publicKey) \ --output-pubkey "./stake-pool-keys/stake-account-$i.json" echo "$(cat ./stake-pool-keys/stake-account-$i.json | jq -r .publicKey)" >> $OUTPUT_FILE done kill $VAL_PID ``` -------------------------------- ### Install spl-token CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token.mdx Installs the spl-token command-line utility for experimenting with SPL tokens. Requires Rust to be installed. ```console $cargo install spl-token-cli ``` -------------------------------- ### Create SPL Token Mint with Transfer Fee (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This command-line interface (CLI) example shows how to create a new SPL token mint with a specified transfer fee. It requires the spl-token CLI tool to be installed and configured. The command takes the fee in basis points and the maximum fee as arguments. ```console $ spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token --transfer-fee 50 5000 Creating token Dg3i18BN7vzsbAZDnDv3H8nQQjSaPUTqhwX41J7NZb5H under program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb Address: Dg3i18BN7vzsbAZDnDv3H8nQQjSaPUTqhwX41J7NZb5H Decimals: 9 Signature: 39okFGqW23wQZ1HqH2tdJvtFP5aYgpfbmNktCZpV5XKTpKuA9xJmvBmrBwcLdfAT632VEC4y4dJJfDoeAvMWRPYP ``` -------------------------------- ### Install SPL Token Lending CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-lending/cli/README.md Installs the SPL Token Lending CLI using Cargo, the Rust package manager. This command assumes you have Rust and Cargo installed on your system. ```shell cargo install spl-token-lending-cli ``` -------------------------------- ### Install Node Modules for Integration Tests Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-swap/README.md Installs the necessary Node.js modules required for running integration tests, typically from the './js' directory. ```sh npm i ``` -------------------------------- ### Create Immutable Token Account with CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This example demonstrates how to explicitly create a token account with immutable ownership using the Solana Program Library's CLI. It covers token creation and then the account creation with the immutable flag. ```console $ spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token Creating token CZxztd7SEZWxg6B9PH5xa7QwKpMCpWBJiTLftw1o3qyV under program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb Address: CZxztd7SEZWxg6B9PH5xa7QwKpMCpWBJiTLftw1o3qyV Decimals: 9 Signature: 4fT19YaE3zAscj71n213K22M3wDSXgwSn39RBCVtiCTxMX7pZhAoHywP2QMKqWpZMB5vT7diQ8QaFp3abHztpyPC $ solana-keygen new -o account.json $ spl-token create-account CZxztd7SEZWxg6B9PH5xa7QwKpMCpWBJiTLftw1o3qyV account.json --immutable Creating account EV2xsZto1TRqehewwWHUUQm68X6C6MepBSkbfZcVdShy Signature: 5NqXiE3LPFnufnZhcwKPoZt7DaPR7qwfhmRr9W9ykhNM7rnu6MDdx7n5eTpEisiaSET2R4fZW7a91Ai6pCuskXF8 ``` -------------------------------- ### Install spl-feature-proposal CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/feature-proposal.md Installs the command-line utility for managing feature proposals. Requires Rust and Cargo to be installed. ```shell cargo install spl-feature-proposal-cli ``` -------------------------------- ### Create Token-2022 Mint with Confidential Transfers (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/confidential-token/quickstart.md This command creates a new Token-2022 mint and enables confidential transfers. The `auto` keyword allows any user to permissionlessly configure their account for confidential transfers. Alternatively, `manual` can be used to restrict this functionality to approved users. Mint configuration for confidential transfers must be done at creation time. ```console spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token --enable-confidential-transfers auto ``` -------------------------------- ### Install Honggfuzz for Fuzz Testing Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-swap/README.md Installs the Rust version of honggfuzz, a coverage-guided fuzzer, which is used to test the Token Swap program. ```sh cargo install honggfuzz ``` -------------------------------- ### Install libssl for Ubuntu Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/README.md This command sequence installs the `libssl1.1` package on Ubuntu, which may resolve shared library loading errors. It involves downloading a `.deb` file and using `dpkg` to install it. Ensure you are in a compatible Ubuntu environment before execution. ```bash wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1l-1ubuntu1.2_amd64.deb sudo dpkg -i libssl1.1_1.1.1l-1ubuntu1.2_amd64.deb ``` -------------------------------- ### Install @solana/spl-token JS Library Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token.mdx Provides instructions for installing the Solana SPL Token JavaScript library using Yarn or npm package managers. ```bash yarn add @solana/spl-token ``` ```bash npm install @solana/spl-token ``` -------------------------------- ### Install Single Pool CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/single-pool.mdx Instructions to install the Single Pool command-line program using Cargo. This program simplifies interaction with the single pool program. Ensure Rust is installed before running. ```console $ cargo install spl-single-pool-cli ``` -------------------------------- ### Install @solana/spl-token-group with npm or yarn Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-group/js/README.md Instructions for installing the @solana/spl-token-group library and its dependency @solana/web3.js using either npm or yarn package managers. ```shell npm install --save @solana/spl-token-group @solana/web3.js@1 ``` ```shell yarn add @solana/spl-token-group @solana/web3.js@1 ``` -------------------------------- ### Initialize Mint Account with MintCloseAuthority Extension (Rust) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/onchain.md Demonstrates calculating space, rent, and creating a mint account with the `MintCloseAuthority` extension before initializing the mint. This is specific to Token-2022. ```rust use spl_token_2022::{ extension::ExtensionType, instruction::*, state::Mint, }; use solana_sdk::{system_instruction, transaction::Transaction}; // Calculate the space required using the `ExtensionType` let space = ExtensionType::try_calculate_account_len::(&[ExtensionType::MintCloseAuthority]).unwrap(); // get the Rent object and calculate the rent required let rent_required = rent.minimum_balance(space); // and then create the account using those parameters let create_instruction = system_instruction::create_account(&payer.pubkey(), mint_pubkey, rent_required, space, token_program_id); // Important: you must initialize the mint close authority *BEFORE* initializing the mint, // and only when working with Token-2022, since the instruction is unsupported by Token. let initialize_close_authority_instruction = initialize_mint_close_authority(token_program_id, mint_pubkey, Some(close_authority)).unwrap(); let initialize_mint_instruction = initialize_mint(token_program_id, mint_pubkey, mint_authority_pubkey, freeze_authority, 9).unwrap(); // Make the transaction with all of these instructions let create_mint_transaction = Transaction::new(&[create_instruction, initialize_close_authority_instruction, initialize_mint_instruction], Some(&payer.pubkey)); // Sign it and send it however you want! ``` -------------------------------- ### Find Accounts with Withheld Tokens (JavaScript) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This JavaScript example demonstrates how to find accounts that have withheld tokens. It iterates through all accounts for a given mint and checks for any accumulated withheld amounts. ```jsx const allAccounts = await connection.getProgramAccounts(TOKEN_2022_PROGRAM_ID, { commitment: 'confirmed', filters: [ { memcmp: { offset: 0, bytes: mint.toString(), }, }, ], }); const accountsToWithdrawFrom = []; for (const accountInfo of allAccounts) { const account = unpackAccount(accountInfo.account, accountInfo.pubkey, TOKEN_2022_PROGRAM_ID); const transferFeeAmount = getTransferFeeAmount(account); if (transferFeeAmount !== null && transferFeeAmount.withheldAmount > BigInt(0)) { accountsToWithdrawFrom.push(accountInfo.pubkey); } } ``` -------------------------------- ### Start Local Docusaurus Development Server using npm Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/README.md Starts a local development server for Docusaurus. This command enables live reloading, allowing developers to see changes reflected in the browser without manual restarts. ```shell npm run start ``` -------------------------------- ### Transfer Tokens with Checked Fee (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This CLI example demonstrates how to transfer tokens with an expected fee. The transfer only succeeds if the provided fee matches the calculated fee, preventing unexpected charges. ```console $ spl-token create-account Dg3i18BN7vzsbAZDnDv3H8nQQjSaPUTqhwX41J7NZb5H Creating account 7UKuG4W68hW9eGrDms6BenRf8DCEHKGN49xewtWyB5cx Signature: 6h591BMuguh9TtSdQPRPcPy97mLqJiybeaxGVZzD8mvPEsYypjZ2jjKgHzji5FGh8CJE3NAzqrqGxfyMdnbWrs7 $ solana-keygen new -o destination.json $ spl-token create-account Dg3i18BN7vzsbAZDnDv3H8nQQjSaPUTqhwX41J7NZb5H destination.json Creating account 5wY8fiMZG5wGbQmtzKgqqEEp4vsCMJZ53RXEagUUWhEr Signature: 2SyA17AJRWLH2j7svgxgW7nouUGioeWoRDWjz2Wq8j1eisThezSvqgN4NbHfj9uWmDh2XRp56ttZtHV1SxaUC7ys $ spl-token mint Dg3i18BN7vzsbAZDnDv3H8nQQjSaPUTqhwX41J7NZb5H 1000000000 Minting 1000000000 tokens Token: Dg3i18BN7vzsbAZDnDv3H8nQQjSaPUTqhwX41J7NZb5H Recipient: 7UKuG4W68hW9eGrDms6BenRf8DCEHKGN49xewtWyB5cx Signature: 5MFJGpLaWe3yLLU8X4ax3KofeqPVzdxJsa3ScjChJJHJawKsRx4og9eaFkWn3CPF7JXaxdj5v4LdAW56LiNTuP6s $ spl-token transfer --expected-fee 0.000005 Dg3i18BN7vzsbAZDnDv3H8nQQjSaPUTqhwX41J7NZb5H 1000000 destination.json Transfer 1000000 tokens Sender: 7UKuG4W68hW9eGrDms6BenRf8DCEHKGN49xewtWyB5cx Recipient: 5wY8fiMZG5wGbQmtzKgqqEEp4vsCMJZ53RXEagUUWhEr Signature: 3hc3CCiETiuCArJ6yZ76ScyfMeK1rw8CTfZ3aDGnYoEMeoqXfSNAtnM3ATFjm7UihthzEkEWzeUfWL4qqqB4ofgv ``` -------------------------------- ### Example: Create Lending Market CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-lending/cli/README.md An example of creating a lending market using the SPL Token Lending CLI. This showcases the actual values for program ID, fee payer, and market owner. ```shell spl-token-lending \ --program 6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH \ --fee-payer owner.json \ create-market \ --market-owner JAgN4SZLNeCo9KTnr8EWt4FzEV1UDgHkcZwkVtWtfp6P # Creating lending market 7uX9ywsk1X2j6wLoywMDVQLNWAqhDpVqZzL4qm4CuMMT # Signature: 51mi4Ve42h4PQ1RXjfz141T6KCdqnB3UDyhEejviVHrX4SnQCMx86TZa9CWUT3efFYkkmfmseG5ZQr2TZTHJ8S95 ``` -------------------------------- ### Update Solana Tests for Token and Token-2022 Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/onchain.md This example demonstrates how to use the `test-case` crate in Rust to run tests against both the standard Token program and the Token-2022 program. It involves modifying test functions to accept a `token_program_id` parameter. ```rust #[test_case(spl_token::id() ; "Token Program")] #[test_case(spl_token_2022::id() ; "Token-2022 Program")] #[tokio::test] async fn test_swap(token_program_id: Pubkey) { // Test logic using token_program_id ... } ``` -------------------------------- ### Withdraw Confidential Tokens (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/confidential-token/quickstart.md This command enables a user to move tokens from their available confidential balance back to their non-confidential balance. Ensure all pending balances are applied before running this command to guarantee all tokens are available for withdrawal. ```console spl-token withdraw-confidential-tokens --address ``` -------------------------------- ### Transfer Confidential Tokens (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/confidential-token/quickstart.md This command allows a user to transfer tokens from their available confidential balance to another recipient's confidential account. The operation involves multiple dependent transactions and takes a few seconds to complete. ```console spl-token transfer --confidential ``` -------------------------------- ### Initialize Token Account with ImmutableOwner Extension (Rust) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/onchain.md Shows how to calculate space, rent, and create a token account with the `ImmutableOwner` extension before initializing the account. This extension is supported by both Token and Token-2022 programs. ```rust use spl_token_2022::{ extension::ExtensionType, instruction::*, state::Account, }; use solana_sdk::{system_instruction, transaction::Transaction}; // Calculate the space required using the `ExtensionType` let space = ExtensionType::try_calculate_account_len::(&[ExtensionType::ImmutableOwner]).unwrap(); // get the Rent object and calculate the rent required let rent_required = rent.minimum_balance(space); // and then create the account using those parameters let create_instruction = system_instruction::create_account(&payer.pubkey(), account_pubkey, rent_required, space, token_program_id); // Important: you must initialize immutable owner *BEFORE* initializing the account let initialize_immutable_owner_instruction = initialize_immutable_owner(token_program_id, account_pubkey).unwrap(); let initialize_account_instruction = initialize_account(token_program_id, account_pubkey, mint_pubkey, owner_pubkey).unwrap(); // Make the transaction with all of these instructions let create_account_transaction = Transaction::new(&[create_instruction, initialize_immutable_owner_instruction, initialize_account_instruction], Some(&payer.pubkey)); // Sign it and send it however you want! ``` -------------------------------- ### Create Non-Transferable Mint with CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This command-line interface example demonstrates the creation of a new SPL token mint with the non-transferable feature enabled using the spl-token CLI. It outputs the new token's address and other relevant details. ```console $ spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token --enable-non-transferable Creating token 7De7wwkvNLPXpShbPDeRCLukb3CRzCNcC3iUuHtD6k4f under program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb Address: 7De7wwkvNLPXpShbPDeRCLukb3CRzCNcC3iUuHtD6k4f Decimals: 9 Signature: 2QtCBwCo2J9hf2Prd2t4CBBUxEXQCBSSD5gkNc59AwhxsKgRp92czNAvwWDxjeXGFCWSuNmzAcD19cEpqubovDDv ``` -------------------------------- ### Deploy Token Lending Program using Solana CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-lending/README.md Deploys the compiled Token Lending program binaries to the Solana Devnet. Requires owner keypair, program ID keypair, and the compiled program file. ```shell solana program deploy \ -k owner.json \ --program-id lending.json \ target/deploy/spl_token_lending.so ``` -------------------------------- ### Configure Solana CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token.mdx Demonstrates how to configure the Solana CLI, including setting the RPC URL for different clusters and specifying a default keypair file or hardware wallet. ```console $ solana config get Config File: ${HOME}/.config/solana/cli/config.yml RPC URL: https://api.mainnet-beta.solana.com WebSocket URL: wss://api.mainnet-beta.solana.com/ (computed) Keypair Path: ${HOME}/.config/solana/id.json ``` ```console $ solana config set --url https://api.devnet.solana.com ``` ```console $ solana config set --keypair ${HOME}/new-keypair.json ``` ```console $ solana config set --keypair usb://ledger/ ``` -------------------------------- ### Transfer Tokens with Checked Fee (JavaScript) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This JavaScript example shows how to perform a token transfer with a checked fee using the Solana Program Library. It involves creating accounts, minting tokens, and then executing the transfer with a specified fee. ```jsx const mintAmount = BigInt(1_000_000_000); const owner = Keypair.generate(); const sourceAccount = await createAccount( connection, payer, mint, owner.publicKey, undefined, undefined, TOKEN_2022_PROGRAM_ID ); await mintTo( connection, payer, mint, sourceAccount, mintAuthority, mintAmount, [], undefined, TOKEN_2022_PROGRAM_ID ); const accountKeypair = Keypair.generate(); const destinationAccount = await createAccount( connection, payer, mint, owner.publicKey, accountKeypair, undefined, TOKEN_2022_PROGRAM_ID ); const transferAmount = BigInt(1_000_000); const fee = (transferAmount * BigInt(feeBasisPoints)) / BigInt(10_000); await transferCheckedWithFee( connection, payer, sourceAccount, mint, destinationAccount, owner, transferAmount, decimals, fee, [], undefined, TOKEN_2022_PROGRAM_ID ); ``` -------------------------------- ### Install Token and Token Lending CLIs using Cargo Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-lending/README.md Installs the necessary command-line interface tools for token management and the Token Lending program using the Rust package manager, Cargo. ```shell cargo install spl-token-cli cargo install spl-token-lending-cli ``` -------------------------------- ### Configure Token Account for Confidential Transfers (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/confidential-token/quickstart.md After creating a standard token account, this command configures it for confidential transfers. Only the account owner can perform this action and set the encryption key. This is a prerequisite for depositing or receiving confidential tokens. ```console spl-token create-account spl-token configure-confidential-transfer-account --address ``` -------------------------------- ### Create Token Account with Required Memo Transfers (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx Demonstrates the CLI commands to create a new token, create an associated account for that token, and then enable required memo transfers for the newly created account. This process involves multiple steps using the `spl-token` utility. ```console $ spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token Creating token EbPBt3XkCb9trcV4c8fidhrvoeURbDbW87Acustzyi8N under program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb Address: EbPBt3XkCb9trcV4c8fidhrvoeURbDbW87Acustzyi8N Decimals: 9 Signature: 2mCoV3ujSUArgZMyayiYtLZp2QzpqKx3NXnv9W8DpinY39rBU2yGmYLfp2tZ9uZqVbfJ6Mf3SqDHexdCcFcDAEvc $ spl-token create-account EbPBt3XkCb9trcV4c8fidhrvoeURbDbW87Acustzyi8N Creating account 4Uzz67txwYbfYpF8r5UGEMYJwhPAYQ5eFUY89KTYc2bL Signature: 57wZHDaQtSzszDkusrnozZNj5PemQhpqHMEFLWFKpqASCErcDuBuYuEky5g3evHtkjMrKgh1s3aEap1L8y5UhW5W $ spl-token enable-required-transfer-memos 4Uzz67txwYbfYpF8r5UGEMYJwhPAYQ5eFUY89KTYc2bL Signature: 5MnWtrhMK32zkbacDMwBNft48VAUpr4EoRM87hkT9AFYvPgPEU7V7ERV6gdfb3kASri4wnUnr13hNKuYJ66pD8Fs ``` -------------------------------- ### Deposit Confidential Tokens (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/confidential-token/quickstart.md This command moves tokens from a user's non-confidential balance to their confidential balance within a configured account. After the deposit, the tokens are no longer visible in the non-confidential balance. This is a necessary step before performing confidential transactions. ```console spl-token deposit-confidential-tokens --address ``` -------------------------------- ### Create Lending Market CLI Usage Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-lending/cli/README.md Demonstrates the command-line interface for creating a new lending market. Requires specifying the lending program ID, a fee payer, and the desired market owner. ```shell spl-token-lending \ --program PUBKEY \ --fee-payer SIGNER \ create-market \ --market-owner PUBKEY ``` -------------------------------- ### Create Non-Transferable Mint with JavaScript (JS) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This JavaScript example uses the @solana/web3.js and @solana/spl-token libraries to programmatically create a new SPL token mint with the non-transferable extension enabled. It handles account creation, airdropping SOL for fees, and transaction signing. ```javascript import { clusterApiUrl, sendAndConfirmTransaction, Connection, Keypair, SystemProgram, Transaction, LAMPORTS_PER_SOL, } from '@solana/web3.js'; import { createInitializeNonTransferableMintInstruction, createInitializeMintInstruction, getMintLen, ExtensionType, TOKEN_2022_PROGRAM_ID, } from '@solana/spl-token'; (async () => { const connection = new Connection(clusterApiUrl('devnet'), 'confirmed'); const payer = Keypair.generate(); const airdropSignature = await connection.requestAirdrop(payer.publicKey, 2 * LAMPORTS_PER_SOL); await connection.confirmTransaction({ signature: airdropSignature, ...(await connection.getLatestBlockhash()) }); const mintAuthority = Keypair.generate(); const decimals = 9; const mintKeypair = Keypair.generate(); const mint = mintKeypair.publicKey; const mintLen = getMintLen([ExtensionType.NonTransferable]); const lamports = await connection.getMinimumBalanceForRentExemption(mintLen); const transaction = new Transaction().add( SystemProgram.createAccount({ fromPubkey: payer.publicKey, newAccountPubkey: mint, space: mintLen, lamports, programId: TOKEN_2022_PROGRAM_ID, }), createInitializeNonTransferableMintInstruction(mint, TOKEN_2022_PROGRAM_ID), createInitializeMintInstruction(mint, decimals, mintAuthority.publicKey, null, TOKEN_2022_PROGRAM_ID) ); await sendAndConfirmTransaction(connection, transaction, [payer, mintKeypair], undefined); })(); ``` -------------------------------- ### Create Token Mint and Account (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token.mdx Demonstrates the creation of a new token mint and an associated account using the `spl-token` CLI. It also shows how to update the mint authority to the previously created multisig account. ```bash $ spl-token create-token Creating token 4VNVRJetwapjwYU8jf4qPgaCeD76wyz8DuNj8yMCQ62o Signature: 3n6zmw3hS5Hyo5duuhnNvwjAbjzC42uzCA3TTsrgr9htUonzDUXdK1d8b8J77XoeSherqWQM8mD8E1TMYCpksS2r $ spl-token create-account 4VNVRJetwapjwYU8jf4qPgaCeD76wyz8DuNj8yMCQ62o Creating account EX8zyi2ZQUuoYtXd4MKmyHYLTjqFdWeuoTHcsTdJcKHC Signature: 5mVes7wjE7avuFqzrmSCWneKBQyPAjasCLYZPNSkmqmk2YFosYWAP9hYSiZ7b7NKpV866x5gwyKbbppX3d8PcE9s $ spl-token authorize 4VNVRJetwapjwYU8jf4qPgaCeD76wyz8DuNj8yMCQ62o mint 46ed77fd4WTN144q62BwjU2B3ogX3Xmmc8PT5Z3Xc2re Updating 4VNVRJetwapjwYU8jf4qPgaCeD76wyz8DuNj8yMCQ62o Current mint authority: 5hbZyJ3KRuFvdy5QBxvE9KwK17hzkAUkQHZTxPbiWffE New mint authority: 46ed77fd4WTN144q62BwjU2B3ogX3Xmmc8PT5Z3Xc2re Signature: yy7dJiTx1t7jvLPCRX5RQWxNRNtFwvARSfbMJG94QKEiNS4uZcp3GhhjnMgZ1CaWMWe4jVEMy9zQBoUhzomMaxC ``` -------------------------------- ### Create Immutable Token Account with JavaScript Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This JavaScript example shows how to programmatically create a token account with immutable ownership using the Solana Program Library and web3.js. It involves setting up a connection, creating a mint, and then creating the account with specific system program instructions. ```jsx import { clusterApiUrl, sendAndConfirmTransaction, Connection, Keypair, SystemProgram, Transaction, LAMPORTS_PER_SOL, } from '@solana/web3.js'; import { createAccount, createMint, createInitializeImmutableOwnerInstruction, createInitializeAccountInstruction, getAccountLen, ExtensionType, TOKEN_2022_PROGRAM_ID, } from '@solana/spl-token'; (async () => { const connection = new Connection(clusterApiUrl('devnet'), 'confirmed'); const payer = Keypair.generate(); const airdropSignature = await connection.requestAirdrop(payer.publicKey, 2 * LAMPORTS_PER_SOL); await connection.confirmTransaction({ signature: airdropSignature, ...(await connection.getLatestBlockhash()) }); const mintAuthority = Keypair.generate(); const decimals = 9; const mint = await createMint( connection, payer, mintAuthority.publicKey, mintAuthority.publicKey, decimals, undefined, undefined, TOKEN_2022_PROGRAM_ID ); const accountLen = getAccountLen([ExtensionType.ImmutableOwner]); const lamports = await connection.getMinimumBalanceForRentExemption(accountLen); const owner = Keypair.generate(); const accountKeypair = Keypair.generate(); const account = accountKeypair.publicKey; const transaction = new Transaction().add( SystemProgram.createAccount({ fromPubkey: payer.publicKey, newAccountPubkey: account, space: accountLen, lamports, programId: TOKEN_2022_PROGRAM_ID, }), createInitializeImmutableOwnerInstruction(account, TOKEN_2022_PROGRAM_ID), createInitializeAccountInstruction(account, mint, owner.publicKey, TOKEN_2022_PROGRAM_ID) ); await sendAndConfirmTransaction(connection, transaction, [payer, accountKeypair], undefined); })(); ``` -------------------------------- ### Apply Pending Confidential Token Balance (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/confidential-token/quickstart.md When an account receives confidential tokens, they initially appear in a 'pending' balance. This command makes those pending funds available for immediate use by moving them to the 'available' balance. It should be run before withdrawing or transferring available confidential tokens. ```console spl-token apply-pending-balance --address ``` -------------------------------- ### Run Fuzz Tests with Honggfuzz Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-swap/README.md Executes fuzz tests on the Token Swap program using honggfuzz from the './program/fuzz' directory. This command initiates the fuzzing process for 'token-swap-instructions'. ```sh cargo hfuzz run token-swap-instructions ``` -------------------------------- ### Create Token Mint with Transfer Hook (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This command creates a new SPL token mint that is configured with a transfer hook. The transfer hook is a program that will be executed whenever tokens are transferred. This example uses the spl-token CLI and specifies the program ID for the transfer hook. ```console $ spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token --transfer-hook 7N4HggYEJAtCLJdnHGCtFqfxcB5rhQCsQTze3ftYstVj Creating token HFg1FFaj4PqFHmkYrqbZsarNJEZT436aXAXgQFMJihwc under program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb Address: HFg1FFaj4PqFHmkYrqbZsarNJEZT436aXAXgQFMJihwc Decimals: 9 Signature: 3ug4Ejs16jJgEm1WyBwDDxzh9xqPzQ3a2cmy1hSYiPFcLQi9U12HYF1Dbhzb2bx75SSydfU6W4e11dGUXaPbJqVc ``` -------------------------------- ### Example: Add Reserve to Lending Market CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-lending/cli/README.md An example demonstrating how to add a reserve to a lending market using the SPL Token Lending CLI. It includes specific values for all required parameters, including Pyth oracle accounts. ```shell spl-token-lending \ --program 6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH \ --fee-payer owner.json \ add-reserve \ --market-owner owner.json \ --source-owner owner.json \ --market 7uX9ywsk1X2j6wLoywMDVQLNWAqhDpVqZzL4qm4CuMMT \ --source AJ2sgpgj6ZeQazPPiDyTYqN9vbj58QMaZQykB9Sr6XY \ --amount 5.0 \ --pyth-product 8yrQMUyJRnCJ72NWwMiPV9dNGw465Z8bKUvnUC8P5L6F \ --pyth-price BdgHsXrH1mXqhdosXavYxZgX6bGqTdj5mh2sxDhF8bJy # Adding reserve 69BwFhpQBzZfcp9MCj9V8TLvdv9zGfQQPQbb8dUHsaEa # Signature: 2yKHnmBSqBpbGdsxW75nnmZMys1bZMbHiczdZitMeQHYdpis4eVhuMWGE29hhgtHpNDjdPj5YVbqkWoAEBw1WaU # Signature: 33x8gbn2RkiA5844eCZq151DuVrYTvUoF1bQ5xA3mqkibJZaJja2hj8RoyjKZpZqg2ckcSKMAeqWbMeWC6vAySQS # Signature: 3dk79hSgzFhxPrmctYnS5dxRhojfKkDwwLxEda9bTXqVELHSL4ux8au4jwvL8xuraVhaZAmugCn4TA1YCfLM4sVL ``` -------------------------------- ### Build Solana Program with Cargo Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/token-swap/README.md Command to build a development version of the Token Swap program using cargo-sbf, the standard build tool for Solana programs. ```sh cargo build-sbf ``` -------------------------------- ### Create Associated Token Account with Immutable Ownership (CLI) Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This example shows how to create an associated token account, which inherently includes the immutable owner extension. It demonstrates that explicitly specifying the --immutable flag is unnecessary as it's a default behavior for Token-2022 associated accounts. ```console $ spl-token create-account CZxztd7SEZWxg6B9PH5xa7QwKpMCpWBJiTLftw1o3qyV Creating account 4nvfLgYMERdNbbf1pADUSp44XukAyjeWWXCMkM1gMqC4 Signature: w4TRYDdCpTfmQh96E4UNgFFeiAHphWNaeYrJTu6bGyuPMokJrKFR33Ntj3iNQ5QQuFqom2CaYkhXiX9sBpWEW23 $ spl-token create-account CZxztd7SEZWxg6B9PH5xa7QwKpMCpWBJiTLftw1o3qyV --immutable Creating account 4nvfLgYMERdNbbf1pADUSp44XukAyjeWWXCMkM1gMqC4 Note: --immutable specified, but Token-2022 ATAs are always immutable, ignoring Signature: w4TRYDdCpTfmQh96E4UNgFFeiAHphWNaeYrJTu6bGyuPMokJrKFR33Ntj3iNQ5QQuFqom2CaYkhXiX9sBpWEW23 ``` -------------------------------- ### Reallocate and enable required memo transfers using CLI Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This CLI example demonstrates enabling required memo transfers for an SPL token account. The CLI automatically handles reallocation if the account does not have sufficient space for the extension. It shows creating an account and then enabling the memo transfer feature. ```console $ spl-token create-account EbPBt3XkCb9trcV4c8fidhrvoeURbDbW87Acustzyi8N Creating account 4Uzz67txwYbfYpF8r5UGEMYJwhPAYQ5eFUY89KTYc2bL Signature: 57wZHDaQtSzszDkusrnozZNj5PemQhpqHMEFLWFKpqASCErcDuBuYuEky5g3evHtkjMrKgh1s3aEap1L8y5UhW5W $ spl-token enable-required-transfer-memos 4Uzz67txwYbfYpF8r5UGEMYJwhPAYQ5eFUY89KTYc2bL Signature: 5MnWtrhMK32zkbacDMwBNft48VAUpr4EoRM87hkT9AFYvPgPEU7V7ERV6gdfb3kASri4wnUnr13hNKuYJ66pD8Fs ``` -------------------------------- ### Initiate SPL Feature Proposal Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/feature-proposal.md This command initiates a feature proposal by creating a proposal configuration file and submitting it to the Solana cluster. It requires a JSON file detailing the proposal. The output provides key addresses and metrics for the proposal. Ensure the `--confirm` flag is used for actual initiation after reviewing the output. ```bash $ spl-feature-proposal propose feature-proposal.json Feature Id: HQ3baDfNU7WKCyWvtMYZmi51YPs7vhSiLn1ESYp3jhiA Token Mint Address: ALvA7Lv9jbo8JFhxqnRpjWWuR3aD12uCb5KBJst4uc3d Distributor Token Address: GK55hNft4TGc3Hg4KzbjEmju8VfaNuXK8jQNDTZKcsNF Acceptance Token Address: AdqKm3mSJf8AtTWjfpA5ZbJszWQPcwyLA2XkRyLbf3Di Number of validators: 376 Tokens to be minted: 134575791.53064314 Tokens required for acceptance: 90165780.3255309 (67%) Token distribution file: feature-proposal.csv JSON RPC URL: http://api.mainnet-beta.solana.com Add --confirm flag to initiate the feature proposal ``` ```bash $ spl-feature-proposal propose feature-proposal.json --confirm ``` -------------------------------- ### Transfer tokens with memo using JavaScript Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This JavaScript example shows how to programmatically transfer SPL tokens with a memo using the Solana Web3.js and SPL Token libraries. It includes creating associated token accounts, minting tokens, creating memo and transfer instructions, and sending the transaction. ```javascript const sourceTokenAccount = await createAssociatedTokenAccount( connection, payer, mint, payer.publicKey, undefined, TOKEN_2022_PROGRAM_ID ); await mintTo(connection, payer, mint, sourceTokenAccount, mintAuthority, 100, [], undefined, TOKEN_2022_PROGRAM_ID); const transferTransaction = new Transaction().add( createMemoInstruction('Hello, memo-transfer!', [payer.publicKey]), createTransferInstruction(sourceTokenAccount, destination, payer.publicKey, 100, [], TOKEN_2022_PROGRAM_ID) ); await sendAndConfirmTransaction(connection, transferTransaction, [payer], undefined); ``` -------------------------------- ### Deposit Stakes into Solana Stake Pool Source: https://github.com/honeycomb-protocol/solana-program-library/blob/master/docs/src/stake-pool/quickstart.md The `deposit.sh` script facilitates depositing stakes into the Solana stake pool. It can be used to create new stakes from SOL or deposit existing stake accounts. This example shows creating new stakes for validators specified in a file, with a given amount. ```bash ./deposit.sh keys/stake-pool.json local_validators.txt 10 ```