Got a few questions regarding storage limitations of smart contract.
- What is the maximum number of bytes of data that I can send for a single transaction?
- Is there a size limit to the storage of a smart contract?
Tezos Stack Exchange is a question and answer site for users, experts, and developers of the Tezos blockchain project. It only takes a minute to sign up.Sign up to join this community
number of bytes per transaction for a single transaction is limited
several constants, in particular an upper size of for operations
max_operation_data_length and the hard gas limits for operations
and blocks (a block contains a set of operations):
"max_operation_data_length": 16384, "hard_gas_limit_per_operation": "800000", "hard_gas_limit_per_block": "8000000", "cost_per_byte": "1000", "hard_storage_limit_per_operation": "60000",
These constants can be obtained by a RPC call if you have a running node:
tezos-client rpc get /chains/main/blocks/head/context/constants | jq
max_operation_data_length is in bytes, meaning that you
have a an upper limit of of ~16kB for the parameter per
transaction. You would also have to remove the size needed other data
in transaction, such as sender, recipient, etc.
The gas limits
hard_gas_limit_per_operation indirectly limit both maximum storage
and transaction size. Each time a smart contract is invoked, the node
passes through the following phases:
Each of these phases consumes gas. Larger parameter increases the gas consumption in phase 2-4. Larger storage increases gas consumption in phases 1-5. It follows that storage and parameter size are limited by the hard gas limits. However, I do not have any hard numbers, but you could simulate using tezos-client to obtain estimates.
Finally, for your second question, which is already partially
answered by 1. AFAIK, there is no explicit fixed limit on the storage of a
smart contract. However, after a
certain size, the storage of contract can no longer be decoded,
because doing so would exceed the hard gas limits. Another limiting
factor is funds. The
costs_per_byte is currently at 1000
mutez. This means that each additional kB costs ~1tz (currently ~= 3usd) to store, payed by
the sender of transaction that increase storage.
We also have to consider the constant
hard_storage_limit_per_operation. Whenever a transaction is
injected on the network, it is associated with a storage limit.
Typically, it is set by the user, to ensure that their transaction
does not provoke an unintended amount of storage burn. If the size
of the storage size diff resulting from applying the transaction
exceeds the storage limit, then the transaction is rejected. The
hard_storage_limit_per_operation gives the highest
storage limit that can be set, and thus also limits the maximum
storage size increase per transaction. It follows that the
storage of a contract cannot increase with more than 60000 bytes
per transaction. Note that such a transaction would cost ~180 usd today.