Read Contract State
Read from a smart contract on Arweave
Last updated
Was this helpful?
Read from a smart contract on Arweave
Last updated
Was this helpful?
The readContractState
function enables reading the contract state from a deployed contract based on the input parameters.
The function is called as follows:
The following params are available for this function and they must be passed in as an object:
environment: 'local' | 'testnet' | 'mainnet'
: The environment in which the smart contract was created in. The testnet
is a pseudo testing environment created on top of the mainnet
with the help of custom tags.
evaluationOptions : object
(optional) : Evaluation options define rules on how a contract will be evaluated during reading contract state. Read more about to learn about the available configurations and their uses.
contractTxId: string
: The contractTxId
is a unique identifier received upon contract creation. This helps the writeContract
to identify the contract to interact with.
cacheOptions : object
(optional) : Contract state is cached for fast retrieval and seamless experience. Custom configurations can be passed in as an object for more control over the caching process. This includes an inMemory
option enabling the storage of cache in local memory. By default, the contract state is cached in a database. The dbLocation
can be configured with the options outlined in these .
The function call returns the following data:
cachedValue: EvalStateResult
: The cachedValue
is an object that stores the state, the validity of the state and any errors faced while reading the state. If the readContract
function is called immediately after a writeContract
call, the cached state is optimistically updated assuming the write call occurs successfully, while the interaction continues to be processed on the actual network (in cases of using the testnet
and mainnet
.
result: object
: The result
object returns easy to understand information showing the status of the read call. status: 200
and statusText: 'SUCCESSFUL'
indicate that information has been successfully read from the contract.
readContract: SortKeyCacheResult
: The readContract
object returns the sortKey
and cachedValue
. Read more .
sortKey: string
: The sortKey
is a value that uses to sort contract transactions.