SPL Token Program

repository·main·Indexed 41 days ago

https://github.com/solana-program/token

A Solana blockchain program and development environment for creating and managing fungible and non-fungible tokens (NFTs). It includes the spl-token-interface crate (v3.0.0) for standardized token interactions, a JavaScript client for core token operations and batching, and p-token, a compute-optimized reimplementation using the pinocchio framework.

Tokens
16.9K
Snippets
47
Records
77
Agent score
52%

What's inside SPL Token

  1. Overview of the SPL Token program

    main
    The SPL Token program is a Solana blockchain program designed to support both fungible and non-fungible tokens (NFTs). It provides the core interface and implementation that third-party developers use to create, manage, and transfer tokens on the Solana network. For comprehensive technical details and deep-dive documentation, refer to the official SPL Token docs.
  2. Overview of p-token

    main
    p-token is a reimplementation of the SPL Token program built using the pinocchio framework. It is designed to optimize Compute Unit (CU) usage while maintaining full byte-for-byte compatibility with the original SPL Token implementation. This means it supports the exact same instruction and account layouts as the standard SPL Token program.
  3. Use the Token Interface for fungible and non-fungible tokens

    main
    The spl-token-interface provides a standardized interface on the Solana blockchain. This allows third-party developers to create and interact with both fungible tokens (FTs) and non-fungible tokens (NFTs) using a consistent set of rules and structures. By implementing or utilizing this interface, your programs can ensure compatibility with the broader Solana token ecosystem.
  4. Key features of p-token

    main

    The p-token program provides the following technical advantages:

    • no_std crate: Optimized for minimal environment requirements.
    • SPL Token Compatibility: Uses the same instruction and account layouts as the original SPL Token program, ensuring seamless integration.
    • Minimal CU usage: Optimized to consume fewer compute units during execution.
  5. Build and test the Rust client

    main

    To build and test the generated Rust library for the Token program, run the test command from the root of the repository. This command will automatically start a new local validator if one is not currently running before executing the Rust client tests.

    pnpm clients:js:test
  6. Build and test the JavaScript client manually

    main

    If you prefer to work directly within the client directory, you must first build the program .so file that LiteSVM requires, then install dependencies and run the build/test commands using pnpm.

    1. Build the program .so from the root.
    2. Navigate to the client directory.
    3. Install dependencies, build, and run tests.
    # Build the program `.so` that LiteSVM loads.
    make build-sbf-pinocchio-program
    
    # Go into the client directory and run the tests.
    cd clients/js
    pnpm install
    pnpm build
    pnpm test
  7. Run JavaScript client tests from the repository root

    main

    To build the client and run the full test suite using LiteSVM (which runs in-process and does not require a local validator), execute the following command from the root of the repository. This command handles dependency installation, client building, and test execution.

    make test-js-clients-js
  8. Add external program dependencies to your validator

    main

    If your program depends on external programs (e.g., other SPL programs), you can instruct the local validator to fetch them from mainnet automatically.

    1. Add the program addresses to the program-dependencies array in your program's Cargo.toml:
    program-dependencies = [
      "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
      "noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",
    ]
    1. Rebuild your program and restart the validator to apply the changes:
    pnpm programs:build
    pnpm validator:restart
    program-dependencies = [
      "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
      "noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",
    ]
    pnpm programs:build
    pnpm validator:restart
  9. Managing multiple Solana programs

    main

    Programs are located in the program folder at the root of the repository. While only one program is generated by default, you can add multiple programs.

    Important: When adding a new program folder, you must add it to the members array in the root Cargo.toml file. This ensures the programs are recognized by the build, test, format, and lint scripts.