The Solana ZK Compressed Token Wallet is a cutting-edge mini-application designed to showcase the power and flexibility of Light Protocol's compressed tokens. This application allows users to create and interact with Solana wallets on-demand, with a specific focus on zk (zero-knowledge) compressed tokens. It is designed to only be used on Solana Devnet for demo purposes and is not intended for production use. Private keys are stored in the browser's local storage. Again: This is not intended for production use.
Compressed tokens are an innovative solution in the Solana ecosystem that allows for more efficient storage and management of token data. It specifically addresses the high storage cost associated with token accounts allowing users to avoid this cost almost entirely. While it would normally cost ~0.002 SOL to create an ATA (associated token account) on-chain, with compressed accounts it costs 0.0000053 SOL. That's a reduction of ~400%! Additionally, a brand new account can receive a USDC deposit of a decompressed -> compressed USDC token within the same transaction, and then decompresses it as a withdrawal for a total of 0.0000153 SOL in fees. This allows the end user to completely avoid creating an ATA for this account while still being able to interact with the uncompressed USDC token. Here's a brief overview of how this work:
- Data Compression: Compressed tokens use advanced data compression techniques to reduce the on-chain storage footprint of token accounts.
- Zero-Knowledge Proofs: They leverage zero-knowledge (ZK) technology to maintain a small footprint while ensuring the validity of transactions.
- Merkle Trees: Compressed tokens utilize Merkle trees to store and verify large amounts of data efficiently.
- Cost-Effective: By reducing on-chain storage, compressed tokens significantly lower the cost of creating and managing token accounts.
- Scalability: This technology enables the creation of a much larger number of token accounts without incurring the high storage costs associated with regular token accounts.
- Compatibility: Compressed tokens maintain compatibility with existing Solana infrastructure and can interact seamlessly with regular SPL tokens.
To learn more about compressed tokens and the technology behind them, check out these resources:
- ZK Compression
- Helius Blog: ZK Compression
- Light Protocol Documentation
- Light Protocol: Compressed Token JS Library
- Photon - Helius' Solana ZK Compression Explorer
- Dynamic Wallet Creation: Generate new Solana wallets instantly within the application. (Does not require connecting a wallet)
- Basic Persistence: Save your wallet addresses locally in the browser's local storage for convenience (Including a user's private keys).
- Compressed Account Interaction: Seamlessly interact with zk compressed accounts.
- USDC Transactions:
- Receive USDC to a wallet
- Send USDC to a compressed account (including your own)
- Send USDC to a regular Solana wallet
- send compressed USDC to a regular Solana wallet (including your own)
- send compressed USDC to a compressed account
- Real-time Balance Updates: View and track wallet balances in real-time (note: updates may take up to 10 seconds to propagate).
- Transaction History: Access a basic history of wallet transactions.
- Helius API Integration: Utilize the Helius API (Photon) to fetch and manage compressed account information.
- Frontend: Next.js with React
- Styling: Tailwind CSS
- Blockchain Interaction: Solana Web3.js, Light Protocol Compressed Token JS Library
- State Management: React Context API
- Notifications: React Toastify
Key components to investigate for your own project:
- WalletsStateContext: Central state management for wallet data.
- ApiContext: Manages API interactions, particularly with Helius.
- Wallet Component: Displays individual wallet information.
- WalletHistory Component: Shows transaction history for each wallet.
- WalletActions Component: Handles wallet operations like sending funds.
-
Clone the repository:
git clone https://github.com/gitteri/solana-zk-compression.git
-
Install dependencies:
cd compressed-wallet npm install
-
Set up environment variables: Create a
.env.local
file in the root directory and add:NEXT_PUBLIC_HELIUS_API_KEY=your_helius_api_key
- Note: you can set desired Solana environment by setting the
NEXT_PUBLIC_NETWORK
environment variable todevnet
ormainnet
respectively. If you chose to use mainnet, be sure to use small amounts of funds as the wallets generated are not secure for production use.
- Note: you can set desired Solana environment by setting the
-
Run the development server:
npm run dev
-
Open
http://localhost:3000
in your browser.
-
Creating a Wallet:
- Click on the "Create New Wallet" button on the homepage.
- A new wallet will be generated and added to your list.
- Note that wallets will be saved to your localstorage for improved UX.
-
Viewing Wallet Details:
- Click on a wallet heading in the list to view its details.
- You'll see the address, balances, transaction history, and actions you can take.
-
Sending USDC:
- In the wallet details page, use the "Send USDC" or "Send USDC Compressed" form.
- The "Select Balance to Send" dropdown allows you to choose from existing balances in your wallet (either USDC or compressed USDC).
- Enter the recipient's address and the amount to send.
- Note: you can choose from your existing wallets or enter a new one.
-
Receiving USDC:
- In the wallet details page, click the "Receive USDC" button.
- Copy the address and share it with Circle's USDC faucet to receive USDC.
- Note: be sure to select Solana when using the faucet.
- This is a demo application and should not be used for managing real funds without proper security audits.
- Private keys are stored in the browser's local storage. In a production environment, more secure key management solutions should be implemented.
- Support for Token Extensions based tokens like PYUSD.
- Explore using a custom state tree instead of the default one.
Contributions to the Compressed Wallet project are welcome. Please follow these steps:
- Fork the repository.
- Create a new branch for your feature.
- Commit your changes and push to your fork.
- Create a pull request with a detailed description of your changes.
- Light protocol for the zero-knowledge compressed accounts infrastructure and libraries
- Helius for their comprehensive API services.
For more information or support, please open an issue in the GitHub repository.