### Project Setup and Script Execution Source: https://github.com/solana-program/memo/blob/main/README.md Installs project dependencies using pnpm and provides commands for building, testing, formatting, and linting the Solana program. ```sh pnpm install pnpm programs:build pnpm programs:test pnpm programs:format pnpm programs:lint ``` -------------------------------- ### Build @solana/spl-memo from Source Source: https://github.com/solana-program/memo/blob/main/clients/js-legacy/README.md Provides a step-by-step guide to build the `@solana/spl-memo` library from its source code. This includes cloning the repository, navigating to the JavaScript client directory, installing dependencies using PNPM, building the library, and running tests. ```shell git clone https://github.com/solana-program/memo.git ``` ```shell cd clients/js-legacy ``` ```shell pnpm install ``` ```shell pnpm build ``` ```shell pnpm test ``` -------------------------------- ### Install, Build, and Test JavaScript Client Source: https://github.com/solana-program/memo/blob/main/clients/js/README.md Installs dependencies, builds the JavaScript client, and runs its tests. This sequence is typically performed after navigating to the client directory. ```shell # Go into the client directory and run the tests. cd clients/js pnpm install pnpm build pnpm test ``` -------------------------------- ### Install @solana/spl-memo Source: https://github.com/solana-program/memo/blob/main/clients/js-legacy/README.md Installs the `@solana/spl-memo` library and `@solana/web3.js` version 1 using either npm or yarn package managers. ```shell npm install --save @solana/spl-memo @solana/web3.js@1 ``` ```shell yarn add @solana/spl-memo @solana/web3.js@1 ``` -------------------------------- ### p-memo Program Log Output Example Source: https://github.com/solana-program/memo/blob/main/p-memo/README.md Illustrates the typical log output from the p-memo program, showing the invocation, signer information, memo content, and final status. This output is generated using `sol_log_pubkey` and `pinocchio-log`. ```text 1: Program PMemo11111111111111111111111111111111111111 invoke [1] 2: Program log: Signed by: 3: Program log: 1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM 4: Program log: Memo (len 60): 5: Program log: why does spl memo use 36000 cus to print len 60 msg of ascii 6: Program PMemo11111111111111111111111111111111111111 consumed 537 of 1400000 compute units 7: Program PMemo11111111111111111111111111111111111111 success ``` -------------------------------- ### Local Validator Management Source: https://github.com/solana-program/memo/blob/main/README.md Scripts to manage the local Solana validator, including starting, restarting, and stopping the validator service. ```sh pnpm validator:start pnpm validator:restart pnpm validator:stop ``` -------------------------------- ### Run JavaScript Client Tests Source: https://github.com/solana-program/memo/blob/main/clients/js/README.md Executes tests for the JavaScript client by starting a local validator if necessary. This command ensures the client functions correctly against a running Solana environment. ```shell pnpm clients:js:test ``` -------------------------------- ### Building p-memo Source: https://github.com/solana-program/memo/blob/main/p-memo/README.md Command to compile the p-memo Solana program using the SBF toolchain. This is a standard build process for Solana programs. ```bash cargo build-sbf ``` -------------------------------- ### TypeScript: Create Memo Instruction Source: https://github.com/solana-program/memo/blob/main/README.md This TypeScript snippet demonstrates creating a memo instruction using the `@solana-program/memo-client`. It's functionally similar to the JavaScript version but with TypeScript typings. ```typescript import { TransactionInstruction } from '@solana/web3.js'; import { encode } from '@solana/accounts'; // Assuming you have a memo program ID and a memo message const MEMO_PROGRAM_ID = new web3.PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'); const memoMessage: string = 'Hello Solana from TypeScript!'; const createMemoInstruction = (message: string): TransactionInstruction => { const data = encode(message); return new TransactionInstruction({ keys: [], // No accounts needed for a simple memo programId: MEMO_PROGRAM_ID, data: data, }); }; const instruction: TransactionInstruction = createMemoInstruction(memoMessage); console.log(instruction); ``` -------------------------------- ### Rust: Initialize Memo Program Source: https://github.com/solana-program/memo/blob/main/README.md This snippet demonstrates how to initialize the SPL Memo Program in Rust. It sets up the program's state and handles account validation. ```rust use solana_program::{ account_info::{next_account_info, AccountInfo}, entrypoint, entrypoint::ProgramResult, msg, pubkey::Pubkey, program_error::ProgramError, }; entrypoint!(process_instruction); pub fn process_instruction( program_id: &Pubkey, accounts: &[AccountInfo], instruction_data: &[u8], ) -> ProgramResult { msg!("SPL Memo Program entrypoint"); let account_iter = &mut accounts.iter(); let memo_account = next_account_info(account_iter)?; // Basic validation: Ensure the memo account is a signer if !memo_account.is_signer { return Err(ProgramError::MissingRequiredSignature); } // Process the memo data (instruction_data) let memo_string = std::str::from_utf8(instruction_data) .map_err(|_| ProgramError::InvalidInstructionData)?; msg!("Memo: {}", memo_string); Ok(()) } ``` -------------------------------- ### Testing p-memo Source: https://github.com/solana-program/memo/blob/main/p-memo/README.md Command to execute the unit tests for the p-memo program. It requires the SBF output directory to be set correctly. ```bash SBF_OUT_DIR=../target/deploy cargo test ``` -------------------------------- ### IDL and Client Generation Source: https://github.com/solana-program/memo/blob/main/README.md Commands for generating Interface Definition Languages (IDLs) and client libraries for the Solana program. It also includes a combined script to generate both IDLs and clients. ```sh pnpm generate:idls pnpm generate:clients pnpm generate ``` -------------------------------- ### Build and Test Rust Client Source: https://github.com/solana-program/memo/blob/main/clients/rust/README.md This command builds and tests the Rust client for the Solana Memo program. It ensures a local validator is running and executes the tests. ```sh pnpm clients:js:test ``` -------------------------------- ### Build Programs and Restart Validator Source: https://github.com/solana-program/memo/blob/main/clients/js/README.md Builds the Solana programs and restarts the local validator. This is a prerequisite for running client-side tests or interacting with the programs locally. ```shell # Build your programs and start the validator. pnpm programs:build pnpm validator:restart ``` -------------------------------- ### JavaScript: Create Memo Instruction Source: https://github.com/solana-program/memo/blob/main/README.md This JavaScript snippet shows how to create a memo instruction using the `@solana-program/memo` client library. It's used to send a memo message within a Solana transaction. ```javascript import { TransactionInstruction } from '@solana/web3.js'; import { encode } from '@solana/accounts'; // Assuming you have a memo program ID and a memo message const MEMO_PROGRAM_ID = new web3.PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'); const memoMessage = 'Hello Solana!'; const createMemoInstruction = (message: string): TransactionInstruction => { const data = encode(message); return new TransactionInstruction({ keys: [], // No accounts needed for a simple memo programId: MEMO_PROGRAM_ID, data: data, }); }; const instruction = createMemoInstruction(memoMessage); console.log(instruction); ``` -------------------------------- ### Lint and Format JavaScript Client Source: https://github.com/solana-program/memo/blob/main/clients/js/README.md Provides scripts for maintaining code quality. 'lint' checks for code style issues, while 'lint:fix' attempts to automatically correct them. 'format' and 'format:fix' handle code formatting. ```shell pnpm lint pnpm lint:fix pnpm format pnpm format:fix ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.