Skip to main content

Overview

Deploying NullGraph to devnet involves three key steps:
  1. Build and deploy the Anchor program to Solana devnet
  2. Initialize the protocol by creating the ProtocolState singleton
  3. Update the frontend IDL to match the deployed program
The deployed program ID on devnet is: 2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK

Prerequisites

Before deploying, ensure you have:
  • Completed the local setup
  • Built the program with anchor build
  • At least 2 SOL in your devnet wallet for deployment
  • Configured Solana CLI to devnet: solana config set --url devnet

Deployment Steps

1

Build the program

Compile the Anchor program and generate the IDL:
anchor build
This creates:
  • Compiled program binary: target/deploy/nullgraph.so
  • IDL file: target/idl/nullgraph.json
  • TypeScript types: target/types/nullgraph.ts
2

Fund your wallet

Ensure your wallet has sufficient devnet SOL:
# Check balance
solana balance

# Request airdrop if needed
solana airdrop 2
Program deployment requires ~2 SOL. Make sure you have enough before proceeding.
3

Deploy to devnet

Deploy the program to the Solana devnet cluster:
anchor deploy --provider.cluster devnet
This command:
  • Uploads the compiled program to devnet
  • Uses the program ID from Anchor.toml: 2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK
  • Deducts deployment costs from your wallet
Expected output:
Deploying workspace: https://explorer.solana.com/address/2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK?cluster=devnet
Upgrade authority: <your-wallet-pubkey>
Deploying program "nullgraph"...
Program path: /path/to/nullgraph/target/deploy/nullgraph.so...
Program Id: 2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK
Deploy success
4

Initialize the protocol

Run the one-time initialization script to create the ProtocolState singleton:
npx ts-node scripts/init-protocol.ts
This script:
  • Derives the ProtocolState PDA: ["protocol_state"]
  • Calls initialize_protocol with fee rate of 250 basis points (2.5%)
  • Sets the treasury address
  • Initializes counters (nka_counter, bounty_counter) to zero
This script only needs to run once per deployment. If the PDA already exists, it will fail with “already in use”.
5

Verify deployment

Verify the program deployed successfully:
solana program show 2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK --url devnet
You can also view the program on Solana Explorer:https://explorer.solana.com/address/2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK?cluster=devnet

Anchor Configuration

The deployment configuration is defined in Anchor.toml:
[toolchain]
package_manager = "npm"

[features]
resolution = true
skip-lint = false

[programs.devnet]
nullgraph = "2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "devnet"
wallet = "~/.config/solana/nullgraph.json"

[scripts]
test = "npm test"
FieldDescription
programs.devnet.nullgraphProgram ID for devnet deployment
provider.clusterTarget cluster (devnet, testnet, mainnet-beta)
provider.walletPath to keypair file for deployment authority

Protocol Initialization Details

The initialize_protocol instruction creates the global ProtocolState account:
// scripts/init-protocol.ts
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Nullgraph } from "../target/types/nullgraph";
import { PublicKey, SystemProgram } from "@solana/web3.js";

const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.nullgraph as Program<Nullgraph>;

const [protocolStatePDA] = PublicKey.findProgramAddressSync(
  [Buffer.from("protocol_state")],
  program.programId
);

const treasuryKeypair = anchor.web3.Keypair.generate();

await program.methods
  .initializeProtocol(250) // 2.5% fee
  .accounts({
    authority: provider.wallet.publicKey,
    protocolState: protocolStatePDA,
    treasury: treasuryKeypair.publicKey,
    systemProgram: SystemProgram.programId,
  })
  .rpc();

console.log("Protocol initialized:", protocolStatePDA.toString());
ProtocolState Fields:
FieldTypeInitial ValueDescription
authorityPubkeyDeployer walletProtocol admin
nka_counteru640Auto-incrementing NKA counter
bounty_counteru640Auto-incrementing bounty counter
fee_basis_pointsu16250Fee on settlement (2.5%)
treasuryPubkeyTreasury walletFee collection address
bumpu8PDA bumpPDA derivation seed

Updating the Frontend IDL

After deploying or updating the program, synchronize the frontend IDL:
anchor build
cp target/idl/nullgraph.json app/src/lib/nullgraph.json
cp target/types/nullgraph.ts app/src/lib/nullgraph_types.ts
This ensures the frontend’s Anchor client uses the correct program interface.
If you modify the program and redeploy, you must update the IDL files in the frontend. Mismatched IDLs will cause transaction failures.

Program Upgrades

To upgrade an existing deployment with new program code:
1

Make your code changes

Edit programs/nullgraph/src/lib.rs with your updates.
2

Rebuild the program

anchor build
3

Deploy the upgrade

anchor upgrade target/deploy/nullgraph.so \
  --program-id 2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK \
  --provider.cluster devnet
4

Update the frontend IDL

cp target/idl/nullgraph.json app/src/lib/nullgraph.json
cp target/types/nullgraph.ts app/src/lib/nullgraph_types.ts
Only the upgrade authority (the wallet that deployed the program) can upgrade it. Check the upgrade authority with:
solana program show 2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK --url devnet

Deployment Checklist

  • Built program: anchor build
  • Funded wallet with 2+ SOL: solana balance
  • Deployed program: anchor deploy --provider.cluster devnet
  • Initialized protocol: npx ts-node scripts/init-protocol.ts
  • Verified deployment: solana program show <program-id>
  • Updated frontend IDL: cp target/idl/nullgraph.json app/src/lib/
  • Tested frontend connection: cd app && npm run dev

Deployment Costs

ActionApproximate CostDescription
Program deployment~2 SOLOne-time program account rent + transaction fees
Protocol initialization~0.001 SOLProtocolState PDA creation
NKA submission~0.001 SOLNullResult PDA creation
Bounty creation~0.002 SOLNullBounty + vault PDA creation
Costs are for devnet and may vary. Mainnet costs will be similar but use real SOL.

Verifying On-Chain State

After initialization, verify the ProtocolState account:
# Using Anchor CLI
anchor account protocol-state <protocol-state-pda> --provider.cluster devnet
Or query directly via the frontend hooks:
import { useProtocolState } from './hooks/useProtocolState';

const { data: protocolState, loading } = useProtocolState();
console.log('NKA Counter:', protocolState?.nkaCounter.toString());
console.log('Fee Rate:', protocolState?.feeBasisPoints, 'bps');

Troubleshooting

”Insufficient funds” error

Solution: Request more devnet SOL:
solana airdrop 2

“Program already deployed” error

Solution: Use anchor upgrade instead of anchor deploy:
anchor upgrade target/deploy/nullgraph.so --program-id <program-id> --provider.cluster devnet

“PDA already in use” during initialization

Solution: The protocol is already initialized. Skip the initialization step.

”Transaction simulation failed” on frontend

Solution: Ensure the frontend IDL matches the deployed program:
cp target/idl/nullgraph.json app/src/lib/nullgraph.json
cp target/types/nullgraph.ts app/src/lib/nullgraph_types.ts

Next Steps

Build docs developers (and LLMs) love