Before setting up the project, ensure the following tools are installed:
- Rust: Required for Solana and Anchor development. Install with:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Agave CLI: A Solana client implementation providing tools like
solana-test-validator. Install the latest stable version (e.g., v2.0.5):cargo install --git https://github.com/anza-xyz/agave --tag v2.0.5 --locked solana
- Note: Agave is a community-driven Solana client maintained by Anza, offering the same functionality as the Solana CLI for this project.
- After installation, verify the version:
This should display the installed version (e.g.,
solana --version
solana-cli 2.0.5).
- Node.js: Necessary for Anchor's JavaScript dependencies. Install via
nvmor your package manager:sudo apt install nodejs # On Ubuntu/Debian - Yarn: Preferred package manager for Anchor projects. Install globally:
npm install -g yarn
The Anchor Version Manager (AVM) simplifies managing Anchor versions, ensuring compatibility with Solana programs. Follow these steps to install Anchor:
-
Install AVM:
cargo install anchor-version-manager
-
Install Anchor: Use AVM to install the latest Anchor version (or specify a version, e.g.,
0.30.0):avm install latest
-
Activate Anchor Version: Set the installed version as the active one:
avm use latest
-
Verify Installation: Check that Anchor is installed correctly:
anchor --version
This should display the Anchor version (e.g.,
anchor-cli 0.30.0).
To interact with the Solana blockchain, you need to configure the Agave CLI, generate keypairs, and sync Anchor keys for development and deployment. Follow these steps:
-
Verify Agave CLI Installation: Confirm that the Agave CLI is installed and check the version:
solana --version
This should display the installed version (e.g.,
solana-cli 2.0.5). -
Configure Agave CLI for Local Development: Set the Agave CLI to use the local cluster for testing:
solana config set --url http://localhost:8899For deployment to devnet or mainnet, use:
solana config set --url https://api.devnet.solana.com # For devnet solana config set --url https://api.mainnet-beta.solana.com # For mainnet
-
Generate a Solana Keypair: Create a new keypair for your Solana wallet, which will be used to sign transactions and deploy programs:
solana-keygen new --outfile ~/.config/solana/id.json- This generates a keypair at
~/.config/solana/id.json. - Save the mnemonic phrase securely, as it is required to recover the keypair.
- To verify the keypair, check your public key:
solana-keygen pubkey
- This generates a keypair at
-
Fund the Keypair (Local or Devnet):
- For local testing: Start a local validator and request an airdrop to fund your wallet:
solana-test-validator & # Run in background solana airdrop 10 # Request 10 SOL
- For devnet: Request an airdrop (limited to 2 SOL per request):
solana airdrop 2
- Verify the balance:
solana balance
- For local testing: Start a local validator and request an airdrop to fund your wallet:
-
Sync Anchor Keys: Anchor uses a keypair for program deployment. Sync the Solana keypair with Anchor to ensure consistency:
- Set the Anchor wallet: Update the Anchor configuration to use the Solana keypair:
This command ensures the keypair in
anchor keys sync
~/.config/solana/id.jsonis copied to the Anchor project directory (e.g.,target/deploy/<program-name>-keypair.json). - Verify the program keypair: Check the generated keypair for your program:
Replace
solana-keygen pubkey target/deploy/<program-name>-keypair.json
<program-name>with your Anchor program's name (defined inAnchor.toml).
- Set the Anchor wallet: Update the Anchor configuration to use the Solana keypair:
-
Optional: Import an Existing Keypair: If you have an existing Solana keypair, import it to
~/.config/solana/id.json:solana-keygen recover --outfile ~/.config/solana/id.jsonEnter the mnemonic phrase when prompted, then sync with Anchor:
anchor keys sync
To build the Solana prediction market program, follow these steps:
-
Clone the Repository:
git clone <repository-url> cd <repository-folder>
-
Install JavaScript Dependencies: Anchor projects require Node.js dependencies for testing and deployment. Install them using Yarn:
yarn install
-
Build the Program: Compile the Rust-based Solana program using Anchor:
anchor build
- This generates the program's IDL (Interface Definition Language) in
target/idl/. - The compiled program binary is stored in
target/deploy/. - Ensure the Agave CLI is configured to use the local cluster (
solana config set --url http://localhost:8899) if testing locally.
- This generates the program's IDL (Interface Definition Language) in
- Start local validator:
In separate window:
solana-test-validator -
Deploy the Program: Deploy Rust-based Solana program using Anchor:
anchor deploy
For upgrading an existing program on mainnet/devnet:
If you encounter "Error processing Instruction 2: custom program error: 0x1", it usually means:
-
Program size increased: The new program is larger than the current allocation. Extend the program account first:
# Check current program size solana program show fLpRcgQSJxKeeUogb6M7bWe1iyYQbahjGXGwr4HgHit --url mainnet-beta # Extend program account (add ~100KB buffer for safety) solana program extend fLpRcgQSJxKeeUogb6M7bWe1iyYQbahjGXGwr4HgHit 100000 --url mainnet-beta --keypair ~/.config/solana/fpp-staging.json
-
Then upgrade:
anchor upgrade target/deploy/flipper.so --program-id fLpRcgQSJxKeeUogb6M7bWe1iyYQbahjGXGwr4HgHit
Alternative: Use the helper script:
./scripts/extend_and_upgrade.sh
-
After deploying or upgrading your program, you may want to update the IDL (Interface Definition Language) on Solscan so that transactions and program interactions are displayed correctly.
Method 1: Upload IDL On-Chain (Recommended)
Solscan automatically detects IDLs that are stored on-chain. To upload/update your IDL:
-
First time initialization (if IDL was never uploaded):
anchor idl init \ --filepath target/idl/flipper.json \ fLpRcgQSJxKeeUogb6M7bWe1iyYQbahjGXGwr4HgHit \ --provider.cluster mainnet \ --provider.wallet ~/.config/solana/fpp-staging.json -
Updating existing IDL:
anchor idl upgrade \ --filepath target/idl/flipper.json \ fLpRcgQSJxKeeUogb6M7bWe1iyYQbahjGXGwr4HgHit \ --provider.cluster mainnet \ --provider.wallet ~/.config/solana/fpp-staging.json
Using the helper script:
# For first time initialization
./scripts/update_idl.sh init
# For updating existing IDL
./scripts/update_idl.sh upgradeMethod 2: Manual Upload on Solscan
If the on-chain method doesn't work, you can manually upload the IDL:
- Go to Solscan and create/login to your account
- Navigate to your program page:
https://solscan.io/account/fLpRcgQSJxKeeUogb6M7bWe1iyYQbahjGXGwr4HgHit - Look for an "Upload IDL" or "Verify Program" option in your profile
- Upload the
target/idl/flipper.jsonfile
Note: Make sure to run anchor build first to generate the latest IDL file before uploading.
The project includes comprehensive scripts for managing operators and Address Lookup Tables (ALT) on mainnet.
Use the interactive bash script for easy access to all ALT and operator management functions:
./scripts/mainnet/alt_manager.shThis provides a user-friendly menu interface for:
- Viewing and managing Address Lookup Tables
- Adding, removing, and replacing operators
- Transferring ALT authority to new operators
For automation and CI/CD, use the TypeScript scripts directly:
Address Lookup Tables:
# List all ALT owned by current authority
npx ts-node scripts/mainnet/list_alt.ts
# Transfer all ALT to new authority
NEW_AUTHORITY_PUBKEY=<address> npx ts-node scripts/mainnet/transfer_alt_authority.ts
# Transfer specific ALT
NEW_AUTHORITY_PUBKEY=<address> ALT_ADDRESSES=<addr1,addr2> \
npx ts-node scripts/mainnet/transfer_alt_authority_specific.tsOperator Management:
# Add operator
OPERATOR_PUBKEY=<address> npx ts-node scripts/mainnet/add_operator.ts
# Remove operator
OPERATOR_PUBKEY=<address> npx ts-node scripts/mainnet/remove_operator.ts
# Replace operator
OLD_OPERATOR_PUBKEY=<old> NEW_OPERATOR_PUBKEY=<new> \
npx ts-node scripts/mainnet/replace_operator.tsFor detailed documentation, examples, and troubleshooting:
- Detailed Guide: See scripts/mainnet/README_OPERATORS.md
- Quick Reference: See scripts/mainnet/QUICK_REFERENCE.md
- Authority keypair file at:
~/.config/solana/fpp-staging.json - Sufficient SOL balance for transactions
- Node.js and npm/npx installed