Data storage in Soroban – Ledger Storage

Data storage in Soroban – Ledger Storage

Share the article:

First What is Soroban? 

Theoretical example

In the section we created a simple contract that saves and loads data.
Soroban contracts have storage available for persistent data storage.
Each piece of data is associated with a key, which is used to later retrieve the data.
A contract can only modify its own data.
All stored data has a time to live – TTL.

Let's take a closer look.

We know how to store and retrieve data within the Soroban ledger.
We created a contract that increases a number by one and stores its value in storage - increments it.
The key to storing this value is a variable named COUNTER.
Whenever we want to retrieve the value of a number, we use this variable.

Stored data also has a TTL (time to live) = number of ledgers.
A ledger is a record in the blockchain – an accounting book.
if TTL is not regularly extended, the data is "archived" and they cannot be read.
For example, the function extend_ttl to extend the storage TTL each time the number increases.

Additionally, we could, for example,:

Add a function to the contract get_current_value, which returns the current value of the counter.
Add features like decrement for decrementing the counter or reset to reset it.

How to deploy a contract to Pi?

A contract is a kind of data sentence, just in bytes.
To obtain bytes, we need to assemble computer instructions, i.e. compile them – using pinetwork contract build.
To upload it to the network, we need to install it using the command pinetwork contract install.
After installation, the contract must be incorporated into circulation - that is, it must exist, and its existence is ensured by a new instance in programming.
To say that something exists requires a command pinetwork contract deploy.
At that moment, our contract essentially becomes a specific application, meaning the contract is a program.
By its existence we obtain its ID with the contract deployed using the command pinetwork contract invoke.
We enter the contract ID and the name of the function we want to run.

You might also like:

DONATE

Support this website and turn off ads!

Donate Pi Bazar.eu


Discover more from PI BAZAR – PI NETWORK

Subscribe and get the latest posts sent to your email.