Compare data across devnet and mainnet
Bridge the gap between testing and reality by querying a single address across devnet and mainnet to see how the same code retrieves unique balances and histories from separate networks.
Compare data across devnet and mainnet
The Scenario
So far in this arc, you’ve been reading data from devnet, Solana’s test network. But devnet isn’t the only network. Solana also has mainnet, where real SOL and real tokens live. The two networks are completely separate databases. An address can exist on both, but the data behind it will be different: different balances, different transaction histories, different activity.
This is similar to how a web app might have separate staging and production databases. Same schema, different data. The API calls are identical; only the URL changes.
The Challenge
Query the same address on both devnet and mainnet. Compare the balance and recent transaction activity on each network. Display the results side by side in your terminal.
What You’ll Need
- Your Day 8 project folder with @solana/kit already installed
- A terminal
- A code editor
Steps
In your project folder, create a new file called compare-networks.mjs and use the contents of this gist: https://gist.github.com/matthewrevell/50c97f5d75a52200f14e92392d93a215
Run It
node compare-networks.mjs
You should see output for both devnet and mainnet, showing different balances and different transaction histories for the same address.
What Just Happened
You created two RPC connections, one pointed at devnet and one at mainnet, and ran the same queries against both. The code is identical across all networks. The only difference is the URL you pass to createSolanaRpc.
A few things to notice:
The devnet() and mainnet() helpers from @solana/kit tag your RPC connection with which network it belongs to. This is more than a label. Kit uses this information internally for type safety, so you can’t accidentally pass a devnet RPC where a mainnet one is expected in more complex applications.
The balances will be different. On mainnet, the Token-2022 program holds real value. On devnet, the balance depends on what testing activity has happened. The transaction histories will be completely different, too, because the two networks have separate user sets doing different things.
Mainnet is the live network where real value moves. Devnet is free to use and designed for experimentation. Everything you’ve built in this arc works on both.
Resources
Submission
Share a screenshot showing the balance and transaction data from both devnet and mainnet.