Accessing the Ledger

Learn how you can directly access the Stellar ledger from a zephyr program.

Zephyr's host environment also provides functions to be able to access the ledger maintained by the stellar nodes that live on our server. This grants Zephyr programs first-class access to fast data retrieval and makes up for programs that are omniscient of what's happening in the chain, not only in each ledger close.

There is currently only a limited set of data structures that can be retrieved from the Stellar ledger, we are still developing the others!

Reading contract data entries

You can read contract data entries from the ledger using the following EnvClient methods:

/// Returns the instance object of a certain contract from
/// the host's ledger.
pub fn read_contract_instance(&self, contract: [u8; 32]) -> Result<Option<ContractDataEntry>, SdkError> {}

/// Returns the requested entry object of a certain contract 
/// from the host's ledger.
pub fn read_contract_entry_by_key(&self, contract: [u8; 32], key: ScVal) -> Result<Option<ContractDataEntry>, SdkError> {}

/// Returns all the entry objects of a certain contract 
/// from the host's ledger.
pub fn read_contract_entries(&self, contract: [u8; 32]) -> Result<Vec<ContractDataEntry>, SdkError> {}

/// Returns all the entry objects of a certain contract 
/// from the host's ledger. This function retuns an iteraror
/// over Soroban host objects, and should be used along with the
/// Soroban SDK.
pub fn read_contract_entries_to_env(&self, env: &soroban_sdk::Env, contract: [u8; 32]) -> Result<Map<Val, Val>, SdkError> {}

These functions are quite straightforward and are a good tool for zephyr ingestion programs to fetch directly from the ledger's state, but are even more important for Zephyr Functions which are not in production yet, but will grant powerful on-request access to the ledger.

Last updated

#17:

Change request updated