Solana Program Library Token-2022
repository·main·Indexed 41 days ago
https://github.com/solana-program/token-2022A 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.
What's inside Token-2022
- 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.
Overview of the Token-2022 Interface
mainThe 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.Run tests for the SPL Token CLI
mainTesting the CLI requires a locally built Token-2022 program.
- First, build the Token-2022 program from the repository root:
cargo build-sbf --manifest-path program/Cargo.toml- Then, run the CLI tests using standard Rust testing commands:
cargo testcargo build-sbf --manifest-path program/Cargo.toml cargo testBuild and test the ElGamal pubkey registry program
mainThe 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-registrymake build-sbf-confidential-elgamal-registry make test-confidential-elgamal-registry make format-check-confidential-elgamal-registry make clippy-confidential-elgamal-registryRequirements for running SPL Token Client end-to-end tests
mainThe end-to-end tests in the
spl-token-2022package 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/fixturesand can be regenerated from the source code located inclients/rust-legacy/transfer-hook-test-programs/:spl-transfer-hook-example-downgradespl-transfer-hook-example-failspl-transfer-hook-example-successspl-transfer-hook-example-swapspl-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-paddingspl-transfer-hook-example
Build and test the Token-2022 program
mainThe
token-2022repository contains the core Token-2022 on-chain program located in theprogramdirectory. You can build, test, and lint the program usingmakecommands.Token-2022 Program Commands
make build-sbf-program make test-program make format-check-program make clippy-programmake build-sbf-program make test-program make format-check-program make clippy-programGenerate Token-2022 clients from IDL
mainAfter the program's IDL (Interface Definition Language) is generated, you can automatically generate client libraries for different languages. This requires running
pnpm installonce to set up the environment.pnpm install make generate-clientspnpm install # only need to run this once make generate-clientsBuild and test the Token 2022 Rust client
mainTo build the Token 2022 program and execute the tests for the generated Rust client, run the following commands from the root of the repository:
- Build the SBF program:
make build-sbf-program - Run the Rust client tests:
make test-clients-rust
make build-sbf-program make test-clients-rust- Build the SBF program:
Start and stop the local validator with Token-2022 programs
mainTo run a local validator that includes the Token-2022 and ElGamal registry programs, you must first build both programs.
Setup and Start
- Build the programs (only required once):
make build-sbf-program make build-sbf-confidential-elgamal-registry - Restart the test validator:
make restart-test-validator
Stop
To stop the local validator:
make stop-test-validatormake 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- Build the programs (only required once):
Install @solana/spl-token
mainTo use the
@solana/spl-tokenTypeScript library for interacting with SPL Token and Token-2022 programs, install it along with@solana/web3.jsversion 1.Important Compatibility Note: If you are using
@solana/web3.jsversion 2, do not use this legacy package. Instead, use the@solana-program/tokenand@solana-program/token-2022packages.npm install --save @solana/spl-token @solana/web3.js@1yarn add @solana/spl-token @solana/web3.js@1Run JavaScript client tests from the repository root
mainTo 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-jsBuild the SPL Token CLI locally
mainTo build thespl-token-cliutility from source, usecargo buildwithin the CLI directory.cargo build