Znap.toml
The znap.toml file tells your workspace that it's in a 'znap workspace'. This configuration file contains the environment variables and dependencies of your project.
A Znap configuration file looks like this:
identity = "~/.config/solana/id.json"
rpc_url = "https://api.devnet.solana.com"
[[collections]]
name = "collection-1"
address = "127.0.0.1"
port = 3000
protocol = "http"
[[collections]]
name = "collection-2"
address = "127.0.0.1"
port = 3001
protocol = "http"
Environment variables
- identity: Specifies the path to your local Solana wallet file.
- rpc_url: Specifies the RPC endpoint used by Znap. This is essential for retrieving transaction blockhashes.
Collections
A collections
element defines the configuration for your collection or collections.
- name: Your collection's name
- address: The IP address where your collection will be hosted. Defaults to 127.0.0.1 (your local machine).
- port: The port number where your collection will be accessible.
- protocol: Your collection's protocol. Defaults to http.
Accessing environment variables in code
You can access environment variables, including identity
and rpc_url
, through the ctx
object in your code, for example:
Note: ctx.env.keypair
already accesses your identity wallet through ctx.env.identity
and converts it into a Keypair to simplify your work.
pub fn stake(ctx: Context<SendDonationAction>) -> Result<ActionTransaction> {
let your_project_rpc = ctx.env.rpc_url.to_string();
println!("Your RPC endpoint {}", your_project_rpc);
let keypair = ctx.env.keypair;
let account_pubkey = Signer::pubkey(&keypair);
println!("Your identity public key: {}", &account_pubkey);
}
...