Cookbook Community Meetup - 12pm ET / 5pm GMT every week on Wednesdays



Contributors: Tom Wilson
Last Updated:

Warp (SmartWeave) SDK - ReadState

SmartWeave Contract state is calculated via lazy evaluation, which means, the state evaluation occurs on reads not writes. When reading contracts, the SDK gathers all state interactions, sorts them, and executes them against the source contract using a reduce or fold pattern.

Basic Readstate

const warp = WarpFactory.forMainnet()
const CONTRACT_ID = '_z0ch80z_daDUFqC9jHjfOL8nekJcok4ZRkE_UesYsk'

const result = await warp.contract(CONTRACT_ID).readState()

// log current state

Advanced Readstate

Some contracts either read the state of other contracts, or invoke or write to other contracts, when requesting the state of these contracts it is necessary to set evaluation options.

const warp = WarpFactory.forMainnet()

const result = await warp.contract(CONTRACT_ID)
    internalWrites: true,
    allowBigInt: true

// log current state

Common Evaluation Options

internalWritesEvaluates contracts that contain internal writes to other contracts
allowBigIntEvaluates contracts that use the BigInt primitive you can find out more about bigInt MDN Docsopen in new window
unsafeClientThis value could be allow or skip or throw. You should avoid using unsafeClient in your contracts it can lead to underministic results.

Readstate from specific BlockHeight or Sortkey

You may want to look at a previous state, not the current state, by supplying a blockHeight you can read the state of a contract at a specific block height

const { sortKey, cachedValue } = await contract.readState(1090111)


Reading the current state of SmartWeave Contracts performs state evaluation by pulling all interactions and processing each interaction via a fold method. This approach is unique to the permaweb and requires a unique understanding of how your SmartWeave Contract code is executed.