Transient Storage in Solidity

Published by Mario Oettler on

Last Updated on 25. November 2025 by Mario Oettler

The EVM (Ethereum Virtual Machine) distinguishes between different locations where to store data. One location is the storage. It is written to the blockchain and therefore persistent. The problem however is that it is very expensive and increases the size of the blockchain as every value is written to and read from the disk.

But sometimes it is not necessary to store a value permanently on the blockchain but make it only persistent during one transaction but in multiple call frames.

When using calls, contracts have two ways to exchange data:

  1. Use input/output (parameters): But when calling external contracts, one cannot rely on the values returned. The variable bool locked is stored as memory and thus only available within the function.

Access data stored in the storage (permanently). But as we know, storage is expensive and thus, many developers refrain from using it if possible. 

This is where transient storage enters the stage.

Transient storage uses an empty storage slot, writes data to it and once the transaction is finished, this slot is cleared. The data stored in this slot is available in all functions and smart contracts called during this transaction. This allows data to be shared securely without the risk of manipulation.

Example

In this example, the value in the transient storage variable tval is shared among different contracts. Compared to storing it in the storage variable sval the transient storage approach is much cheaper.

pragma solidity 0.8.30;

contract SC01{
    uint public transient tval;
    uint public sval;

    function startTransientStorage(address sc02_addr) public returns(uint256){
        // setting transient storage
        tval = 200;
        uint256 val;

        // calling SC02 to fetch transient storage
        SC02 a = SC02(sc02_addr);
        val = a.readTransientStorage(address(this));
        return val;
    }

    function startStorage(address sc02_addr) public returns(uint256){
        // setting storage
        sval = 200;
        uint256 val;

        // calling SC02 to fetch storage
        SC02 a = SC02(sc02_addr);
        val = a.readStorage(address(this));
        return val;
    }
}


contract SC02{
    bytes32 constant SLOT = 0;
    function readTransientStorage(address sc01_addr) public view returns(uint256 v){
        uint256 val;
        SC01 a = SC01(sc01_addr);
        val = a.tval();
        return val;
    }

    function readStorage(address sc01_addr) public view returns(uint256 v){
        uint256 val;
        SC01 a = SC01(sc01_addr);
        val = a.sval();
        return val;
    }
}

Categories:

https://blockchain-academy.hs-mittweida.de/wp-content/uploads/2021/04/logo_bcam_rgb_gross.png

Welcome

Blockchain Academy

Continue with credential

No account yet?

Powered by Hidy

Register with Hidy


Register
Sign in

We need the following credential to register:

please select:

To create a new account, we need the following data from you:

We would appreciate the following additional information from you for the creation of your account:

Welcome

Blockchain Academy

Continue with credential

Already have an account?

Powered by Hidy

Sign in with Hidy


Register
Sign in

We need the following credential to log in:

please select:
Do you need assistance?
Click here to open chat.

Privacy Notice: This chat sends your questions to an external AI server.
How can we help you?
  • Please note: All questions, chat history, and feedback are sent to an external AI server for processing. Do not share sensitive personal information.

    All responses are generated by AI. Independently verify and fact-check all information before use.
  • No Chat History yet, start talking...