Skip to main content
Version: Next

Reading and Writing Data to Global State

Casper features several means of reading and writing data to global state, depending on user needs and complexity. Reading data from global state can be done by dApps off-chain or by smart contracts on-chain. Writing data requires on-chain interactions due to the nature of the system. Storage in global state can be accomplished using Dictionaries or NamedKeys.

note

Casper's Condor release shifts NamedKeys to a top-level key type, making them more viable for larger data sets.

Using the Casper JSON-RPC

The query_global_state method available through the JSON-RPC allows users to read data from global state without performing on-chain actions. For more details, see the Querying a Casper Network tutorial.

Using the Casper Rust API

The Casper API includes the following functions for reading and writing to global state:

  • put_key - Stores the given Key under the given name in the current context's named keys
  • get_key - Returns the requested NamedKey from the current context
  • storage::new_uref - Creates a new URef in the current context
  • storage::write - Writes a given value under a previously created URef
  • storage::read - Reads the value from a URef in global state
  • dictionary_put - Writes the given value under the given dictionary_item_key
  • dictionary_get - Retrieves the value stored under a dictionary_item_key

For more details, see the Reading and Writing to Global State using Rust tutorial.