SPL Token Program
repository·main·Indexed 41 days ago
https://github.com/solana-program/tokenA 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.
What's inside SPL Token
- 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.
Overview of p-token
mainp-tokenis a reimplementation of the SPL Token program built using thepinocchioframework. 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.Use the Token Interface for fungible and non-fungible tokens
mainThespl-token-interfaceprovides 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.Use the SPL Token Interface for Fungible and Non-Fungible tokens
mainThespl-token-interfacecrate provides the necessary instructions and constructors to interact with the SPL Token program. This program serves as a common implementation for both Fungible and Non-Fungible (NFT) tokens on Solana.Key features of p-token
mainThe
p-tokenprogram provides the following technical advantages:no_stdcrate: 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.
Build and test the Rust client
mainTo 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:testBuild and test the JavaScript client manually
mainIf you prefer to work directly within the client directory, you must first build the program
.sofile that LiteSVM requires, then install dependencies and run the build/test commands usingpnpm.- Build the program
.sofrom the root. - Navigate to the client directory.
- 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- Build the program
Run JavaScript client tests from the repository root
mainTo 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-jsGenerate IDLs and clients
mainAfter generating your programs' IDLs, you can generate clients using
pnpm generate:clients.To generate both the IDLs and the clients in a single step, use the
generatescript:pnpm generateAdd external program dependencies to your validator
mainIf your program depends on external programs (e.g., other SPL programs), you can instruct the local validator to fetch them from mainnet automatically.
- Add the program addresses to the
program-dependenciesarray in your program'sCargo.toml:
program-dependencies = [ "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s", "noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV", ]- Rebuild your program and restart the validator to apply the changes:
pnpm programs:build pnpm validator:restartprogram-dependencies = [ "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s", "noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV", ]pnpm programs:build pnpm validator:restart- Add the program addresses to the
Managing multiple Solana programs
mainPrograms are located in the
programfolder 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
membersarray in the rootCargo.tomlfile. This ensures the programs are recognized by the build, test, format, and lint scripts.Project setup for SPL Token development
mainTo begin developing with this template, install the necessary NPM dependencies to access the provided scripts and tools.
pnpm install