Solana Program Library Token-2022

repository·main·Indexed 41 days ago

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

A collection of Solana on-chain programs, including the core Token-2022 program and the ElGamal pubkey registry. It provides a standardized interface for creating and managing fungible and non-fungible tokens (NFTs) with advanced features such as confidential computing, transfer hooks, and transfer fees.

Tokens
82.2K
Snippets
283
Records
376
Agent score
53%

What's inside Token-2022

  1. Overview of the Token-2022 program

    main
    The Token-2022 program is a Solana blockchain program designed to support both fungible and non-fungible tokens (NFTs). It provides a standardized interface and implementation that developers can use to create, manage, and interact with various token types on the Solana network.
  2. Overview of the Token-2022 Interface

    main
    The Token-2022 Interface is a token program interface on the Solana blockchain designed to support both fungible and non-fungible tokens (NFTs). It serves as a standard interface that third-party developers can utilize to create and interact with their own custom tokens. For detailed technical specifications and implementation guides, refer to the official Solana Program Docs.
  3. Run tests for the SPL Token CLI

    main

    Testing the CLI requires a locally built Token-2022 program.

    1. First, build the Token-2022 program from the repository root:
    cargo build-sbf --manifest-path program/Cargo.toml
    1. Then, run the CLI tests using standard Rust testing commands:
    cargo test
    cargo build-sbf --manifest-path program/Cargo.toml
    cargo test
  4. Build and test the ElGamal pubkey registry program

    main

    The ElGamal pubkey registry program is located in confidential/elgamal-registry. Use these commands to manage its lifecycle.

    ElGamal Registry Commands

    make build-sbf-confidential-elgamal-registry
    make test-confidential-elgamal-registry
    make format-check-confidential-elgamal-registry
    make clippy-confidential-elgamal-registry
    make build-sbf-confidential-elgamal-registry
    make test-confidential-elgamal-registry
    make format-check-confidential-elgamal-registry
    make clippy-confidential-elgamal-registry
  5. Requirements for running SPL Token Client end-to-end tests

    main

    The end-to-end tests in the spl-token-2022 package require several on-chain programs to be present. Some are provided as built fixtures within the repository, while others must be sourced externally.

    Internal Test Programs

    The following programs are available as built versions in tests/fixtures and can be regenerated from the source code located in clients/rust-legacy/transfer-hook-test-programs/:

    • spl-transfer-hook-example-downgrade
    • spl-transfer-hook-example-fail
    • spl-transfer-hook-example-success
    • spl-transfer-hook-example-swap
    • spl-transfer-hook-example-swap-with-fee

    External Dependencies

    The following programs are required but are not included in this repository and must be provided externally:

    • spl-instruction-padding
    • spl-transfer-hook-example
  6. Build and test the Token-2022 program

    main

    The token-2022 repository contains the core Token-2022 on-chain program located in the program directory. You can build, test, and lint the program using make commands.

    Token-2022 Program Commands

    make build-sbf-program
    make test-program
    make format-check-program
    make clippy-program
    make build-sbf-program
    make test-program
    make format-check-program
    make clippy-program
  7. Generate Token-2022 clients from IDL

    main

    After the program's IDL (Interface Definition Language) is generated, you can automatically generate client libraries for different languages. This requires running pnpm install once to set up the environment.

    pnpm install
    make generate-clients
    pnpm install # only need to run this once
    make generate-clients
  8. Build and test the Token 2022 Rust client

    main

    To build the Token 2022 program and execute the tests for the generated Rust client, run the following commands from the root of the repository:

    1. Build the SBF program: make build-sbf-program
    2. Run the Rust client tests: make test-clients-rust
    make build-sbf-program
    make test-clients-rust
  9. Start and stop the local validator with Token-2022 programs

    main

    To run a local validator that includes the Token-2022 and ElGamal registry programs, you must first build both programs.

    Setup and Start

    1. Build the programs (only required once):
      make build-sbf-program
      make build-sbf-confidential-elgamal-registry
    2. Restart the test validator:
      make restart-test-validator

    Stop

    To stop the local validator:

    make stop-test-validator
    make build-sbf-program # you only need to run this once
    make build-sbf-confidential-elgamal-registry # you only need to run this once
    make restart-test-validator
    
    # To stop
    make stop-test-validator
  10. Install @solana/spl-token

    main

    To use the @solana/spl-token TypeScript library for interacting with SPL Token and Token-2022 programs, install it along with @solana/web3.js version 1.

    Important Compatibility Note: If you are using @solana/web3.js version 2, do not use this legacy package. Instead, use the @solana-program/token and @solana-program/token-2022 packages.

    npm install --save @solana/spl-token @solana/web3.js@1
    yarn add @solana/spl-token @solana/web3.js@1
  11. Run JavaScript client tests from the repository root

    main

    To build and test the JavaScript client automatically, run the following command from the root of the repository. This command will start a new local validator (if one is not already running) and execute the JavaScript client tests.

    make test-js-clients-js