### Interactive Shell Example Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/cli/index.md Demonstrates launching the AnchorPy shell and interacting with an Anchor program's RPC methods. ```console $ cd anchor/examples/tutorial/basic-0 && anchorpy shell Python 3.9.1 (default, Dec 11 2020, 14:32:07) Type 'copyright', 'credits' or 'license' for more information IPython 7.30.1 -- An enhanced Interactive Python. Type '?' for help. Hint: type `workspace` to see the Anchor workspace object. # In [1]:$ await workspace["basic_0"].rpc["initialize"]() Out[1]: '2q1Z8BcsSBikMLEFoeFGhUukfsNYLJx7y33rMZ57Eh4gAHJxpJ9oP9b9aFyrizh9wcuiVtAAxvmBifCXdqWeNLor' ``` -------------------------------- ### Initialize Account with Arguments in JS Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/index.md This JavaScript snippet demonstrates calling an RPC function to initialize an account. It uses the Anchor framework's conventions for account and signer setup. ```javascript // The program to execute. const program = anchor.workspace.Basic1; // The Account to create. const myAccount = anchor.web3.Keypair(); // Create the new account and initialize it with the program. await program.rpc.initialize(new anchor.BN(1234), { accounts: { myAccount: myAccount.Pubkey, user: provider.wallet.Pubkey, systemProgram: SystemProgram.programId, }, signers: [myAccount], }); ``` -------------------------------- ### AnchorPy Shell Command Help Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/cli/index.md Displays the help message for the `anchorpy shell` command, explaining how to start an IPython shell. ```console $ anchorpy shell --help Usage: anchorpy shell [OPTIONS] Start IPython shell with AnchorPy workspace object initialized. Note that you should run `anchor localnet` before `anchorpy shell`. Options: --help Show this message and exit. ``` -------------------------------- ### Install AnchorPy (Core) Source: https://github.com/kevinheavey/anchorpy/blob/main/README.md Install only the core AnchorPy library if you do not need the CLI or Pytest plugin features. ```sh pip install anchorpy ``` -------------------------------- ### Anchorpy Client Gen Command Execution Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/clientgen/index.md Example of executing the anchorpy client-gen command to generate client code from an IDL file into a specified output directory. ```console $ anchorpy client-gen path/to/idl.json ./my_client generating package... generating program_id.py... generating errors.py... generating instructions... generating types... generating accounts... ``` -------------------------------- ### Install AnchorPy with CLI and Pytest Source: https://github.com/kevinheavey/anchorpy/blob/main/README.md Use this command to install AnchorPy with all features, including the CLI and Pytest plugin. Ensure you have Python 3.9 or higher. ```sh pip install anchorpy[cli, pytest] ``` -------------------------------- ### Python Test File for Anchor Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/testing/index.md Example Python test file using Pytest and AnchorPy to test program initialization and updates. Requires pytest-asyncio. Ensure your Anchor.toml is configured to use pytest. ```python # test_basic_1.py import asyncio from pathlib import Path from pytest import fixture, mark from anchorpy import create_workspace, close_workspace, Context, Program from solders.keypair import Keypair from solders.system_program import ID as SYS_PROGRAM_ID # Since our other fixtures have module scope, we need to define # this event_loop fixture and give it module scope otherwise # pytest-asyncio will break. @fixture(scope="module") def event_loop(): """Create an instance of the default event loop for each test case.""" loop = asyncio.get_event_loop_policy().new_event_loop() yield loop loop.close() @fixture(scope="module") async def program() -> Program: workspace = create_workspace() yield workspace["basic_1"] await close_workspace(workspace) @fixture(scope="module") async def initialized_account(program: Program) -> Keypair: my_account = Keypair() await program.rpc["initialize"]( 1234, ctx=Context( accounts={ "my_account": my_account.pubkey(), "user": program.provider.wallet.public_key, "system_program": SYS_PROGRAM_ID, }, signers=[my_account], ), ) return my_account @mark.asyncio async def test_create_and_initialize_account( program: Program, initialized_account: Keypair ) -> None: """Test creating and initializing account in single tx.""" account = await program.account["MyAccount"].fetch(initialized_account.pubkey()) assert account.data == 1234 @mark.asyncio async def test_update_previously_created_account( initialized_account: Keypair, program: Program ) -> None: """Test updating a previously created account.""" await program.rpc["update"]( 4321, ctx=Context(accounts={"myAccount": initialized_account.pubkey()}) ) account = await program.account["MyAccount"].fetch(initialized_account.pubkey()) assert account.data == 4321 ``` -------------------------------- ### Run AnchorPy Unit Tests Source: https://github.com/kevinheavey/anchorpy/blob/main/README.md To contribute to AnchorPy, set up the development environment using uv and run the unit tests with pytest. This command installs all extras and runs tests in the specified directory. ```sh uv run --all-extras pytest tests/unit ``` -------------------------------- ### Calling an Instruction with Generated Client Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/clientgen/index.md Demonstrates how to construct and send an instruction using the generated Python client, including setting up parameters and accounts. ```python from solders.hash import Hash from solders.keypair import Keypair from solders.message import Message from solders.pubkey import Pubkey from solders.transaction import Transaction from anchorpy import Provider from my_client.instructions import some_instruction # call an instruction foo_account = Keypair() # in real use, fetch this from an RPC recent_blockhash = Hash.default() ix = some_instruction({ "foo_param": "...", "bar_param": "...", ... }, { "foo_account": foo_account.pubkey(), # signer "bar_account": Pubkey("..."), ... }) msg = Message(instructions=[instruction], payer=payer.pubkey()) tx = Transaction([payer], msg, recent_blockhash) provider = Provider.local() await provider.send(tx) ``` -------------------------------- ### AnchorPy Init Command Help Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/cli/index.md Shows the help message for the `anchorpy init` command, detailing its usage for creating test files. ```console $ anchorpy init --help Usage: anchorpy init [OPTIONS] PROGRAM_NAME Create a basic Python test file for an Anchor program. This does not replace `anchor init`, but rather should be run after it. The test file will live at `tests/test_$PROGRAM_NAME.py`. Arguments: PROGRAM_NAME The name of the Anchor program. [required] Options: --help Show this message and exit. ``` -------------------------------- ### Initialize Account with Arguments in Python Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/index.md Use this snippet to call an RPC function with arguments and create a new account. AnchorPy requires an explicit Context object for account and signer configuration. ```python import asyncio from solders.keypair import Keypair from solders.system_program import ID as SYS_PROGRAM_ID from anchorpy import create_workspace, close_workspace, Context async def main(): # Read the deployed program from the workspace. workspace = create_workspace() # The program to execute. program = workspace["basic_1"] # The Account to create. my_account = Keypair() # Execute the RPC. accounts = { "my_account": my_account.pubkey(), "user": program.provider.wallet.public_key, "system_program": SYS_PROGRAM_ID } await program.rpc["initialize"](1234, ctx=Context(accounts=accounts, signers=[my_account])) # Close all HTTP clients in the workspace, otherwise we get warnings. await close_workspace(workspace) asyncio.run(main()) ``` -------------------------------- ### Working with Struct Types Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/clientgen/index.md Demonstrates how to create and serialize a struct type using the generated client. ```python # structs from my_client.types import BarStruct bar_struct = BarStruct( some_field="...", other_field="...", ) print(bar_struct.to_json()) ``` -------------------------------- ### Workspaces: Create and Use Program Client (Python) Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/index.md Creates a workspace, retrieves a program client by its snake_case name, and executes an RPC method. Explicitly calls `create_workspace` and `close_workspace`. ```python import asyncio from anchorpy import create_workspace, close_workspace async def main(): # Read the deployed program from the workspace. workspace = create_workspace() program = workspace["basic_0"] # Execute the RPC. await program.rpc["initialize"]() # Close all HTTP clients in the workspace, otherwise we get warnings. await close_workspace(workspace) asyncio.run(main()) ``` -------------------------------- ### Generate and Use Program Client from IDL (Python) Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/index.md Reads a generated IDL, creates a program client, and executes an RPC method. Ensure the IDL file exists and the program ID is correct. Uses a context manager for automatic client closing. ```python from pathlib import Path import asyncio import json from solders.pubkey import Pubkey from anchorpy import Idl, Program async def main(): # Read the generated IDL. with Path("target/idl/basic_0.json").open() as f: raw_idl = f.read() idl = Idl.from_json(raw_idl) # Address of the deployed program. program_id = Pubkey.from_string("") # Generate the program client from IDL. async with Program(idl, program_id) as program: # Execute the RPC. await program.rpc["initialize"]() # If we don't use the context manager, we need to # close the underlying http client, otherwise we get warnings. # await program.close() asyncio.run(main()) ``` -------------------------------- ### Load Program from On-Chain IDL Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/examples.md Initializes a program object using `Program.at` when the program's IDL is stored on-chain. Requires an async client, provider, and wallet. ```python import asyncio from solana.rpc.async_api import AsyncClient from solders.pubkey import Pubkey from anchorpy import Program, Provider, Wallet async def main(): client = AsyncClient("https://api.mainnet-beta.solana.com/") provider = Provider(client, Wallet.local()) # load the Serum Swap Program (not the Serum dex itself). program_id = Pubkey.from_string("22Y43yTVxuUkoRKdm9thyRhQ3SdgQS7c7kB6UNCiaczD") program = await Program.at( program_id, provider ) print(program.idl.name) # swap await program.close() asyncio.run(main()) ``` -------------------------------- ### Fetching and Deserializing an Account Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/clientgen/index.md Shows how to fetch an account by its public key using the generated client and convert it to a JSON object. ```python from solders.pubkey import Pubkey from my_client.accounts import FooAccount # fetch an account addr = Pubkey("...") acc = await FooAccount.fetch(connection, addr) if acc is None: # the fetch method returns null when the account is uninitialized raise ValueError("account not found") # convert to a JSON object obj = acc.to_json() print(obj) # load from JSON acc_from_json = FooAccount.from_json(obj) ``` -------------------------------- ### AnchorPy CLI Help Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/cli/index.md Displays the main help message for the AnchorPy CLI, listing available options and commands. ```console $ anchorpy --help Usage: anchorpy [OPTIONS] COMMAND [ARGS]... AnchorPy CLI. Options: --install-completion [bash|zsh|fish|powershell|pwsh] Install completion for the specified shell. --show-completion [bash|zsh|fish|powershell|pwsh] Show completion for the specified shell, to copy it or customize the installation. --help Show this message and exit. Commands: init Create a basic Python test file for an Anchor program. shell Start IPython shell with AnchorPy workspace object initialized. ``` -------------------------------- ### Anchorpy Client Gen CLI Help Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/clientgen/index.md Displays the help message for the anchorpy client-gen command, outlining its usage and options. ```console $ anchorpy client-gen --help Usage: anchorpy client-gen [OPTIONS] IDL OUT Generate Python client code from the specified anchor IDL. Arguments: IDL Anchor IDL file path [required] OUT Output directory. [required] Options: --program-id TEXT Optional program ID to be included in the code --help Show this message and exit. ``` -------------------------------- ### Using Types as Instruction Arguments Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/clientgen/index.md Shows how to pass generated struct and enum types as arguments when calling an instruction, including passing struct fields as objects. ```python # types are used as arguments in instruction calls (where needed): ix = some_instruction({ "some_struct_field": bar_struct, "some_enum_field": tuple_enum, # ... }, { # accounts # ... }) # in case of struct fields, it's also possible to pass them as objects: ix = some_instruction({ "some_struct_field": { "some_field": "...", "other_field": "...", }, # ..., }, { # accounts # ... }) ``` -------------------------------- ### Generate and Use Program Client from IDL (JS) Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/index.md Reads a generated IDL, creates a program client, and executes an RPC method. Requires Anchor JS library and Node.js environment. ```javascript // Read the generated IDL. const idl = JSON.parse(require('fs').readFileSync('./target/idl/basic_0.json', 'utf8')); // Address of the deployed program. const programId = new anchor.web3.Pubkey(''); // Generate the program client from IDL. const program = new anchor.Program(idl, programId); // Execute the RPC. await program.rpc.initialize(); ``` -------------------------------- ### Working with Enum Types Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/clientgen/index.md Illustrates creating and serializing different kinds of enum variants (tuple, struct, discriminant) using the generated client. ```python # enums from my_client.types import baz_enum tuple_enum = baz_enum.SomeTupleKind((True, False, "some value")) struct_enum = baz_enum.SomeStructKind({ "field1": "...", "field2": "...", }) disc_enum = baz_enum.SomeDiscriminantKind() print(tuple_enum.toJSON(), struct_enum.toJSON(), disc_enum.toJSON()) ``` -------------------------------- ### Handling Program Errors with Generated Client Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/clientgen/index.md Demonstrates how to catch and parse program errors using the generated error classes and utility functions. ```python from solana.rpc.core import RPCException from my_client.errors import from_tx_error from my_client.errors.custom import SomeCustomError try: await provider.send(tx, [payer]) except RPCException as exc: parsed = from_tx_error(exc) raise parsed from exc ``` -------------------------------- ### anchorpy.create_workspace Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Creates a workspace object for interacting with a set of Solana programs defined by an IDL. ```APIDOC ## anchorpy.create_workspace ### Description Convenience function to create a workspace object, which aggregates multiple programs based on their IDLs. ### Function anchorpy.create_workspace ### Parameters (Parameters like `provider`, `idl_path`, `programs` would be listed here if available in source) ### Returns (Return type, likely a workspace object, would be described here if available in source) ``` -------------------------------- ### Workspaces: Create and Use Program Client (JS) Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/index.md Accesses a program client directly from the Anchor JS workspace using its PascalCase name and executes an RPC method. ```javascript // Read the deployed program from the workspace. const program = anchor.workspace.Basic0; // Execute the RPC. await program.rpc.initialize(); ``` -------------------------------- ### anchorpy.Program Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Represents a Solana program and provides methods for interacting with its instructions and accounts. ```APIDOC ## anchorpy.Program ### Description Represents a Solana program, enabling interaction with its instructions and accounts. ### Class anchorpy.Program ### Methods (Details of methods like `instruction`, `account`, `rpc` would be listed here if available in source) ``` -------------------------------- ### Generated Client Directory Structure Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/clientgen/index.md Illustrates the typical directory structure created by the anchorpy client-gen command for a generated Python client. ```treeview . ├── accounts │ ├── foo_account.py │ └── __init__.py ├── instructions │ ├── some_instruction.py │ ├── other_instruction.py │ └── __init__.py ├── types │ ├── bar_struct.py │ ├── baz_enum.py │ └── __init__.py ├── errors │ ├── anchor.py │ ├── custom.py │ └── __init__.py └── program_id.py ``` -------------------------------- ### Pytest Fixture for AnchorPy Workspace Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/testing/index.md Sets up a Pytest fixture that runs 'anchor localnet' and tears it down after tests. Useful for integrating with IDEs or using a debugger. ```python from pytest import fixture, mark from solders.keypair import Keypair from solders.system_program import ID as SYS_PROGRAM_ID from anchorpy import Context, Program, workspace_fixture, WorkspaceType workspace = workspace_fixture("anchor/examples/tutorial/basic-1") # Since our other fixtures have module scope, we need to define # this event_loop fixture and give it module scope otherwise # pytest-asyncio will break. @fixture(scope="module") def event_loop(): """Create an instance of the default event loop for each test case.""" loop = asyncio.get_event_loop_policy().new_event_loop() yield loop loop.close() @fixture(scope="module") def program(workspace: WorkspaceType) -> Program: """Create a Program instance.""" return workspace["basic_1"] @fixture(scope="module") async def initialized_account(program: Program) -> Keypair: """Generate a keypair and initialize it.""" my_account = Keypair() await program.rpc["initialize"]( 1234, ctx=Context( accounts={ "my_account": my_account.pubkey(), "user": program.provider.wallet.public_key, "system_program": SYS_PROGRAM_ID, }, signers=[my_account], ), ) return my_account @mark.asyncio async def test_create_and_initialize_account( program: Program, initialized_account: Keypair, ) -> None: """Test creating and initializing account in single tx.""" account = await program.account["MyAccount"].fetch(initialized_account.pubkey()) assert account.data == 1234 @mark.asyncio async def test_update_previously_created_account( initialized_account: Keypair, program: Program, ) -> None: """Test updating a previously created account.""" await program.rpc["update"]( 4321, ctx=Context(accounts={"my_account": initialized_account.pubkey()}), ) account = await program.account["MyAccount"].fetch(initialized_account.pubkey()) assert account.data == 4321 ``` -------------------------------- ### Fetch Multiple Accounts Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/examples.md Efficiently fetches deserialized account data for multiple accounts simultaneously using `program.account.fetch_multiple`. Supports batching for optimized RPC requests. ```python n_accounts = 200 pubkeys = [initialized_keypair.pubkey()] * n_accounts # noqa: WPS435 data_accounts = await program.account["Data"].fetch_multiple( pubkeys, batch_size=2 ) ``` -------------------------------- ### anchorpy.NamedInstruction Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Represents an instruction with a specific name within an Anchor program. ```APIDOC ## anchorpy.NamedInstruction ### Description Represents a named instruction within an Anchor program, used for clarity and type safety. ### Class anchorpy.NamedInstruction ### Attributes (Attributes like `name`, `program_id`, `accounts`, `args` would be listed here if available in source) ``` -------------------------------- ### anchorpy.SimulateResponse Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Represents the response from simulating a transaction. ```APIDOC ## anchorpy.SimulateResponse ### Description Represents the structured response obtained from simulating a transaction, including logs and error information. ### Class anchorpy.SimulateResponse ### Attributes (Attributes like `value`, `logs`, `err` would be listed here if available in source) ``` -------------------------------- ### Instantiate Struct Type Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/examples.md Builds a struct instance defined in the IDL using `program.type`. This is commonly used when preparing account data for transactions. ```python program.type["TransactionAccount"]( pubkey=multisig.pubkey(), is_writable=True, is_signer=False, ) ``` -------------------------------- ### anchorpy.Context Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Represents the execution context for a Solana transaction. ```APIDOC ## anchorpy.Context ### Description Represents the execution context for a Solana transaction, often used to pass program and provider information. ### Class anchorpy.Context ### Methods (Details of context-related attributes or methods would be listed here if available in source) ``` -------------------------------- ### anchorpy.InstructionCoder Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Encodes and decodes Anchor program instructions. ```APIDOC ## anchorpy.InstructionCoder ### Description Handles the encoding and decoding of Anchor program instructions based on the program's IDL. ### Class anchorpy.InstructionCoder ### Methods (Details of methods like `encode`, `decode` would be listed here if available in source) ``` -------------------------------- ### anchorpy.utils Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Module containing various utility functions for Anchorpy. ```APIDOC ## anchorpy.utils ### Description Contains a collection of utility functions that assist with common tasks in Anchorpy development. ### Module anchorpy.utils ### Functions (Specific utility functions like `to_anchor_id`, `is_valid_program_id` would be listed here if available in source) ``` -------------------------------- ### anchorpy.Provider Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Manages the connection and interaction context with a Solana cluster. ```APIDOC ## anchorpy.Provider ### Description Manages the connection and interaction context with a Solana cluster, including wallet and network configuration. ### Class anchorpy.Provider ### Methods (Details of methods like `send`, `simulate`, `get_balance` would be listed here if available in source) ``` -------------------------------- ### anchorpy.AccountClient Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Client for interacting with a specific account on the Solana blockchain. ```APIDOC ## anchorpy.AccountClient ### Description Provides methods to fetch, parse, and subscribe to changes for a specific Solana account. ### Class anchorpy.AccountClient ### Methods (Details of methods like `fetch`, `subscribe` would be listed here if available in source) ``` -------------------------------- ### anchorpy.Wallet Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Represents a Solana wallet with associated keypair for signing transactions. ```APIDOC ## anchorpy.Wallet ### Description Represents a Solana wallet, typically holding a keypair used for signing transactions. ### Class anchorpy.Wallet ### Methods (Details of methods like `sign_transaction`, `sign_message` would be listed here if available in source) ``` -------------------------------- ### anchorpy.workspace_fixture Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md A pytest fixture for setting up an anchorpy workspace in tests. ```APIDOC ## anchorpy.workspace_fixture ### Description Provides a pytest fixture that automatically sets up and tears down an anchorpy workspace for testing purposes. ### Fixture anchorpy.workspace_fixture ### Usage (Example usage within a pytest test function would be described here if available in source) ``` -------------------------------- ### anchorpy.AccountsCoder Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Encodes and decodes Anchor program account data. ```APIDOC ## anchorpy.AccountsCoder ### Description Handles the encoding and decoding of Anchor program account data based on the program's IDL. ### Class anchorpy.AccountsCoder ### Methods (Details of methods like `encode`, `decode` would be listed here if available in source) ``` -------------------------------- ### anchorpy.IdlProgramAccount Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Represents an account defined in an Anchor program's IDL. ```APIDOC ## anchorpy.IdlProgramAccount ### Description Represents an account structure as defined in an Anchor program's Interface Definition Language (IDL). ### Class anchorpy.IdlProgramAccount ### Attributes (Attributes like `name`, `accounts`, `args` would be listed here if available in source) ``` -------------------------------- ### Anchor.toml Script Configuration Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/testing/index.md Configuration for the Anchor.toml file to set the test script to use Pytest. This enables running Python tests with the `anchor test` command. ```toml [scripts] test = "pytest" ``` -------------------------------- ### anchorpy.ProgramAccount Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Represents an account owned by an Anchor program. ```APIDOC ## anchorpy.ProgramAccount ### Description Represents an account that is owned by an Anchor program, including its address and data. ### Class anchorpy.ProgramAccount ### Attributes (Attributes like `address`, `account` would be listed here if available in source) ``` -------------------------------- ### Dictionary Access in AnchorPy vs. Object Access in Anchor TS Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/comparison_with_anchor_ts.md AnchorPy uses dictionary-style access with square brackets for keys, while Anchor TS uses dot notation for object properties. ```python workspace["basic_1"] ``` ```typescript workspace.basic_1 ``` ```python program.rpc["initialize"]() ``` ```typescript program.rpc.initialize() ``` -------------------------------- ### anchorpy.EventCoder Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Encodes and decodes Anchor program events. ```APIDOC ## anchorpy.EventCoder ### Description Handles the encoding and decoding of Anchor program events based on the program's IDL. ### Class anchorpy.EventCoder ### Methods (Details of methods like `decode` would be listed here if available in source) ``` -------------------------------- ### anchorpy.localnet_fixture Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md A pytest fixture for running tests against a local Solana validator. ```APIDOC ## anchorpy.localnet_fixture ### Description Provides a pytest fixture that starts and manages a local Solana validator for integration testing. ### Fixture anchorpy.localnet_fixture ### Usage (Example usage within a pytest test function would be described here if available in source) ``` -------------------------------- ### anchorpy.EventParser Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Parses event logs emitted by Anchor programs. ```APIDOC ## anchorpy.EventParser ### Description Parses raw event logs from Solana transactions to decode them into structured Anchor events. ### Class anchorpy.EventParser ### Methods (Details of methods like `parse_logs` would be listed here if available in source) ``` -------------------------------- ### anchorpy.Coder Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Base class for encoding and decoding data according to Anchor IDLs. ```APIDOC ## anchorpy.Coder ### Description Base class for various coders (InstructionCoder, EventCoder, AccountsCoder) used for serialization and deserialization based on Anchor IDLs. ### Class anchorpy.Coder ### Methods (Details of methods like `encode`, `decode` would be listed here if available in source) ``` -------------------------------- ### anchorpy.validate_accounts Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Validates account information against an Anchor program's IDL. ```APIDOC ## anchorpy.validate_accounts ### Description Validates that the provided account information conforms to the requirements specified in the program's IDL. ### Function anchorpy.validate_accounts ### Parameters (Parameters like `idl_accounts`, `accounts` would be listed here if available in source) ### Returns (Return type, likely a boolean or None, would be described here if available in source) ``` -------------------------------- ### anchorpy.translate_address Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Translates a program-derived address (PDA) based on seeds and program ID. ```APIDOC ## anchorpy.translate_address ### Description Calculates the address of a Program Derived Address (PDA) given its seeds and the program ID. ### Function anchorpy.translate_address ### Parameters (Parameters like `seeds`, `program_id` would be listed here if available in source) ### Returns (Return type, likely a PublicKey, would be described here if available in source) ``` -------------------------------- ### anchorpy.Event Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Represents a decoded event emitted by an Anchor program. ```APIDOC ## anchorpy.Event ### Description Represents a decoded event emitted by an Anchor program, containing event data and type information. ### Class anchorpy.Event ### Attributes (Attributes like `name`, `data` would be listed here if available in source) ``` -------------------------------- ### Instantiate Enum Type Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/examples.md Creates an instance of an enum type defined in the program's IDL using `program.type`. This is useful for passing enum arguments to instructions. ```python await program.rpc["my_func"](program.type["Side"].Buy()) ``` -------------------------------- ### anchorpy.error Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Module for handling and interpreting Anchor program errors. ```APIDOC ## anchorpy.error ### Description Provides utilities for handling and decoding errors returned by Anchor programs. ### Module anchorpy.error ### Functions/Classes (Specific error-related functions or classes would be listed here if available in source) ``` -------------------------------- ### anchorpy.close_workspace Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/api_reference.md Closes the workspace and cleans up any associated resources. ```APIDOC ## anchorpy.close_workspace ### Description Cleans up resources associated with an anchorpy workspace. ### Function anchorpy.close_workspace ### Parameters (Parameters like `workspace` would be listed here if available in source) ``` -------------------------------- ### Explicit Context Object in AnchorPy RPC Calls Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/comparison_with_anchor_ts.md AnchorPy requires an explicit `Context` object to be passed as a keyword argument for RPC calls, which includes account information. ```python program.rpc["my_func"](ctx=Context({"my_account": my_account})) ``` ```typescript program.rpc["my_func"]({"my_account": my_account}) ``` -------------------------------- ### Snake_case Naming Convention in AnchorPy Source: https://github.com/kevinheavey/anchorpy/blob/main/docs/dynamic_client/comparison_with_anchor_ts.md AnchorPy adopts snake_case for various elements like workspaces, instructions, and account fields to align with Python conventions. ```python workspace["puppet_master"] ``` ```typescript workspace["puppetMaster"] ``` ```python program.rpc["my_func"] ``` ```typescript program.rpc["myFunc"] ``` ```python {"my_account": my_account} ``` ```typescript {"myAccount": my_account} ``` ```python program.type["TransactionAccount"](is_writable=True) ``` ```typescript program.type["TransactionAccount"](isWritable=True) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.