Blockchain & Cryptocurrency Glossary

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • search-icon Clear Definitions
  • search-icon Practical
  • search-icon Technical
  • search-icon Related Terms

Smart Contract State

1 min read
Pronunciation
[smart kon-trakt steyt]
Analogy
Imagine a shared digital whiteboard (the smart contract) that has various pieces of information written on it (its state), like 'Current Game Score: Alice 10, Bob 5' or 'Item Owner: Charlie'. Only the rules of the game programmed into the whiteboard allow these scores or ownership details to be updated, and everyone can see the current information.
Definition
The data that is persistently stored on the blockchain by a smart contract. This data represents the contract's current condition and can include variables, balances, ownership records, or any other information the contract is programmed to manage. The state can be read by anyone and can only be modified by the contract itself according to its programmed rules when transactions are executed.
Key Points Intro
A smart contract's state is its memory on the blockchain, recording all relevant persistent data.
Key Points

Persistent data stored by a smart contract on the blockchain.

Includes all variables and data structures defined within the contract that hold values.

Can only be changed by the execution of the contract's functions in response to transactions.

Publicly readable by anyone interacting with the blockchain.

Preserved between transactions; it's what gives a contract 'memory'.

Example
An ERC-20 token contract's state includes a mapping of user addresses to their token balances, the total supply of the token, and allowance mappings. When a user transfers tokens, the contract's code executes and modifies these balances in its state.
Technical Deep Dive
In Ethereum, a smart contract's state is stored in its 'storage', which is a key-value store where keys and values are typically 256-bit words. This storage is persistent and relatively expensive to use (in terms of gas costs) compared to transient memory used during execution. The state of all contracts collectively forms part of the blockchain's overall world state, which is secured by consensus.

Smart Contract State - Related Articles

No related articles for this term.