Documentation Index
Fetch the complete documentation index at: https://mintlify.com/stellar/rs-soroban-sdk/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheEnv type provides access to the environment the contract is executing within. It provides access to information about the currently executing contract, who invoked it, contract data, functions for signing, hashing, and more.
Most types require access to an Env to be constructed or converted.
Creating an Env
default()
Create a new default Env instance.
Core Methods
storage()
Get a Storage for accessing and updating persistent data owned by the currently executing contract.
events()
Get Events for publishing events associated with the currently executing contract.
ledger()
Get a Ledger for accessing the current ledger information.
deployer()
Get a Deployer for deploying contracts.
crypto()
Get a Crypto for accessing cryptographic functions.
prng()
Get a Prng for accessing pseudo-random number generation functions.
logs()
Get the Logs for logging debug events.
Contract Interaction
current_contract_address()
Get the Address object corresponding to the current executing contract.
invoke_contract()
Invokes a function of a contract that is registered in the Env.
- If the
contract_iddoes not match a registered contract - If
funcdoes not match a function of the referenced contract - If the number of
argsdo not match the argument count - If the contract invocation fails or aborts
- If the return value cannot be converted into type
T
try_invoke_contract()
Invokes a function of a contract and returns an error if the invocation fails for any reason.
authorize_as_current_contract()
Authorizes sub-contract calls on behalf of the current contract.
Test Utilities
register()
Register a contract with the Env for testing.
register_at()
Register a contract at a specific address.
mock_all_auths()
Mock all calls to Address::require_auth() and Address::require_auth_for_args(), having them succeed as if authorization was provided.
auths()
Returns a list of authorization trees that were seen during the last contract invocation.
Error Handling
panic_with_error()
Panic with the given error value.
panic!, but with an error value instead of a string.
Example: