ArweaveKit Docs
  • ArweaveKit
    • Introduction
  • 🔐Wallets
    • Introduction to Wallets
    • Create Wallet
    • Get Wallet Address
    • Get Wallet Balance
    • Wallet Plugins
  • 💳ARWEAVE WALLET KIT
    • Introduction to Arweave Wallet Kit
    • Setup
    • Connect Button
    • Hooks
    • Customization
  • 🏦Transactions
    • Introduction to Transactions
    • Create Transaction
    • Sign Transaction
    • Post Transaction
    • Get Transaction Status
    • Get Transaction
    • Create and Post Transaction with Othent
    • Transaction Plugins
  • 📄SMART CONTRACTS
    • Introduction to Smart Contracts
    • Create Contract
    • Write Contract
    • Read Contract State
    • View Contract State
    • Write Contract with Othent
    • Read Contract with Othent
    • Smart Contract Plugins
  • ✅AUTH
    • Introduction to Auth
    • Connect
    • Disconnect
    • Get Active Address
    • Get Permissions
    • Get Wallet Names
    • Get All Addresses
    • Get Active Public Key
    • Is Installed
    • Log In with Othent
    • Log Out with Othent
    • Get User Details with Othent
    • Auth Plugins
  • 🔐Encryption
    • Introduction to Encryption
    • Encrypt Data with AES
    • Decrypt Data with AES
    • Encrypt AES Key with RSA
    • Decrypt AES Key with RSA
    • Encryption Plugins
  • 🌐GRAPHQL
    • Introduction to GraphQL
    • Query All Arweave Transactions
    • Query Arweave Data
    • Query Arweave Transactions
    • GraphQL Plugins
  • 🗺️RoadMap
    • Features
  • 📘REFERENCES
    • ArweaveKit in Browser Environments
  • 🛠️SUPPORTING TOOLS
    • Arweave StarterKit
Powered by GitBook
On this page
  • Basic Syntax
  • Input Parameters
  • Returned Data

Was this helpful?

  1. SMART CONTRACTS

Read Contract State

Read from a smart contract on Arweave

PreviousWrite ContractNextView Contract State

Last updated 1 year ago

Was this helpful?

The readContractState function enables reading the contract state from a deployed contract based on the input parameters.

To retrieve the result from a contract's read function, it is recommended to utilize the function.

Basic Syntax

The function is called as follows:

import { readContractState } from 'arweavekit/contract'

const readResult = await readContractState({params});

Input Parameters

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.

If the contract was created in a local environment, please make sure thatarlocal is running in the background to be able to interact with the contract. To create one, simply run npx arlocal in the command line. Learn more about arlocal .

  • 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 .

Example
const readResult = await readContractState({
      environment: 'testnet',
      contractTxId: 'CONTRACT_TRANSACTION_ID',
});

Returned Data

The function call returns the following data:

readContract: SortKeyCacheResult {
    sortKey: '000000000000,0000000000000,0000000000000000000000000000000000000000000000000000000000000000',
    cachedValue: EvalStateResult {
      state: [Object],
      validity: {},
      errorMessages: {}
    }
},
result: { status: 200, statusText: 'SUCCESSFUL' }
    • 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.

📄
viewContractState
here
evaluation options
docs
here
warp