0

I'm trying to avoid having to make code changes when I move from testing on localnet to devnet and then mainnet.

One of my account constraints checks the mint for the associated token account, which will be different on each network. is it possible to code all 3 mint addresses with a conditional which will choose which one based on the network it's deployed to?

1 Answer 1

3

The only way to know which network you're on is to through the different genesis hashes: https://docs.solana.com/api/http#getgenesishash

Since you can't access that on-chain, you'll need to manage your builds and deployments carefully. You could do that through Cargo features, ie:

[features]
default = ["mainnet-beta"]
mainnet-beta = []
devnet = []
testnet = []

Then in your code, do something like:

#[cfg(feature = "mainnet-beta")]
const MINT: Pubkey = Pubkey();

#[cfg(feature = "devnet")]
const MINT: Pubkey = Pubkey();

#[cfg(feature = "testnet")]
const MINT: Pubkey = Pubkey();

Then when you build, you pass in the network that you build for as a feature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.