State
Each account has an associated state where it stores its metadata and all the contract-related data (contract's code + storage).
Accounts' states can be read by anyone in the network, but only the account itself can change it.
Each account pays for their own storage by locking a part of their balance proportional to the space used.
Account's Metadataโ
The state keeps track of relevant metadata from the contract. Particularly, the state stores the following fields:
amount
: The accounts balance expressed in yoctoNEAR (1 โ = 1024yโ).code_hash
: A hash of the contract's Wasm file, filled with1s
if no contract is present.storage_usage
: Amount of bytes used for storage by the account (code + metadata + data storage).
You can check an accounts metadata by running the following near cli command:
near state hello-nearverse.testnet
Contract's Stateโ
The state is also the place where both the contract's code and the contract's storage are stored.
The contract's storage is organized as key-value pairs encoded using base64 and JSON serialization (or Borsh in Rust).
You can check an accounts contract state by running the following near cli command:
near view-state hello-nearverse.testnet --finality final --utf8 true
When developing contracts our SDK will handle serializing the storage, so you can focus on what matters.
Paying for Storage (1 โ ~ 100kb)โ
In order to pay for storage, accounts needs to lock a portion of their balance proportional to the amount of data being stored. This means that:
- If more data is added and the state increases โ, the account's balance decreases โ.
- If data is deleted and the state decreases โ, the account's balance increases โ.
Currently, it cost approximately 1 โ to store 100kb of data.