1

I'm working on a Solana program and would like to understand if it's possible to set constant values during program deployment, similar to constructor parameters in other smart contract platforms. Additionally, I'm curious to know if there is a way to update or change these constant values after the program is deployed.

1 Answer 1

2

You can use Rust feature flags for this use-case. These can be used as environment variables, which allow you to set deployment environments, config, and more.

For example, you'll set them in your Cargo.toml file like the following:

[features]
feature-one = []
feature-two = []

and use them in your program like this:

#[cfg(feature = "testing")]
pub const SOME_VARIABLE: usize = 100;

#[cfg(not(feature = "testing"))]
pub const ANOTHER_VARIABLE: usize = 50;

More comprehensive resources on this:

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.