On-Chain Storage | Algorand Developer Portal

On-Chain Storage

In Algorand, when developing an application, data and values can be persistently saved on the decentralized ledger itself. This storage mechanism is known as on-chain storage.

This storage can be global, local, or box storage.

The following section describes the main properties of each storage type.

Global Storage

Global Storage allows storing values on an application. This data will be linked to the application, and any user or client will be able to access the data only by interacting with the application.

Usage example

For example, in a voting application, the total votes for each candidate could be stored in Global Storage. Since these values represent aggregate data for the entire application, they should be accessible to all users and clients.

Storage characteristics

Considerations

When storing data in Global Storage, keep in mind that depending on the type and number of values you want to store, the Minimum Balance Requirement (MBR) of the application creator will be increased according to the following formula:

  100,000*(1+ExtraProgramPages) + (25,000+3,500)*schema.NumUint + (25,000+25,000)*schema.NumByteSlice

Local Storage

Local Storage stores data associated directly with an account that has opted-in to the application. This opt-in mechanism is activated through an opt-in transaction and allows any account to create a relationship and a storage space with the application for storing data for this specific account.

Usage example

When programming a voting application, storing each account’s vote may be necessary, so every user can check the candidate they voted for. This can be achieved by storing a key/value pair in each account’s local storage. This data will only be linked to the specific account that interacted with the smart contract.

Storage characteristics

Considerations

For this storage type, the account must perform an opt-in transaction. When storing data in Local Storage, keep in mind that depending on the type and number of values you want to store, the Minimum Balance Requirement (MBR) of the account that opts-in to the application will increase according to the following formula:

100,000 + (25,000+3,500)*schema.NumUint + (25,000+25,000)*schema.NumByteSlice

Boxes

Box Storage will allow you to store larger amounts of data, associated with the application you’re creating. Every box can store up to 32KB and an application is capable of create as many boxes as it needs.

Usage example

Let’s revisit our voting application example using Box Storage instead of Global and Local Storage. We can store:

This approach eliminates the need for opt-in transactions since we’re not using Local Storage.

Storage characteristics

Considerations

(2500 per box) + (400 * (box size + key size))
(2500) + (400 * (1024+4)) = 413,700 microAlgos