Postage Stamp Batches
A postage batch is required to upload data to Swarm. Postage stamp batches represent right to write data on Swarm's DISC (Distributed Immutable Store of Chunks). The parameters which control the duration and quantity of data that can be stored by a postage batch are depth and amount, with depth determining data volume that can be uploaded by the batch and amount determining storage duration of data uploaded with the batch.
The storage volume and duration are both non-deterministic. Volume is non-deterministic due to the details of how postage stamp batch utilization works. While duration is non-deterministic due to price changes made by the price oracle contract.
Storage volume and depth:
When purchasing stamp batches for larger volumes of data (by increasing the depth value), the amount of data which can be stored becomes increasingly more predictable. For example, at depth 22 a batch can store between 2.28 GB (encrypted, paranoid erasure coding) and 17.18 GB (theoretical max), while at depth 28, a batch can store between 292.67 GB and 1.1 TB of data, and at higher depths the difference between the minimum and maximum storage volumes approach the same value. The effective volume also depends on the encryption and erasure coding settings used. See the effective utilisation tables for the full details.
Storage duration and amount:
The duration of time for which a batch can store data is also non-deterministic since the price of storage is automatically adjusted over time by the price oracle contract. However, limits have been placed on how swiftly the price of storage can change, so there is no danger of a rapid change in price causing postage batches to unexpectedly expire due to a rapid increase in price. You can view a history of price changes by inspecting the events emitted by the oracle contract, or also through the Swarmscan API. As you can see, if and when postage batch prices are updated, the updates are quite small. Still, since it is not entirely deterministic, it is important to monitor your stamp batch TTL (time to live) as it will change along with price oracle changes. You can inspect your batch's TTL using the /stamps endpoint of the API:
root@noah-bee:~# curl -s localhost:1633/stamps | jq
{
"stamps": [
{
"batchID": "f56af59cc2c785a3b45bbf3e46c3c4b20f80379339ef337b5bbf45ebe5629a66",
"utilization": 0,
"usable": true,
"label": "",
"depth": 17,
"amount": "432072000",
"bucketDepth": 16,
"blockNumber": 38498819,
"immutableFlag": true,
"exists": true,
"batchTTL": 82943
}
]
}
Here we can see from the batchTTL that 82943 seconds remain, or approximately 23 hours.
For a deeper understanding of how depth and amount parameters determine the data volume and storage duration of a postage batch, see the postage stamp page.
Fund your node's wallet.
In order to purchase a postage stamp batch, your node's Gnosis Chain address needs to be funded with sufficient xDAI to pay gas for transaction fees on Gnosis Chain as well as sufficient xBZZ to pay for the cost of the postage stamp batch itself.
xBZZ can be obtained from a variety of different centralized and decentralized exchanges. You can find more information on where to obtain xBZZ on the Ethswarm homepage.
xDAI can be obtained from a wide range of centralized and decentralized exchanges. See this list of exchanges from the Gnosis Chain documentation to get started.
You can learn more details from the Fund Your Node section.
Buying a stamp batch
When interacting with the Bee API directly, amount and depth are passed as path parameters:
curl -s -X POST http://localhost:1633/stamps/<amount>/<depth>
And with Swarm CLI, they are set using option flags:
swarm-cli stamp buy --depth <depth value> --amount <amount value>
- API
- Swarm CLI
API
curl -s -X POST http://localhost:1633/stamps/100000000/20
{
"batchID": "8fcec40c65841e0c3c56679315a29a6495d32b9ed506f2757e03cdd778552c6b",
"txHash": "0x51c77ac171efd930eca8f3a77e3fcd5aca0a7353b84d5562f8e9c13f5907b675"
}
Swarm CLI
swarm-cli stamp buy --depth 20 --amount 100000000
Estimated cost: 0.010 BZZ
Estimated capacity: 4.00 GB
Estimated TTL: 5 hours 47 minutes 13 seconds
Type: Mutable
When a mutable stamp reaches full capacity, it still permits new content uploads. However, this comes with the caveat of overwriting previously uploaded content associated with the same stamp.
? Confirm the purchase Yes
Stamp ID: f4b9830676f4eeed4982c051934e64113dc348d7f5d2ab4398d371be0fbcdbf5
Once your batch has been purchased, it will take a few minutes for other Bee nodes in the Swarm to catch up and register your batch. Allow some time for your batch to propagate in the network before proceeding to the next step.
Setting stamp batch parameters and options
When purchasing a batch of stamps there are several parameters and options which must be considered. The depth parameter will control how many chunks can be uploaded with a batch of stamps. The amount parameter determines how much xBZZ will be allocated per chunk, and therefore also controls how long the chunks will be stored. While the immutable header option sets the batch as either mutable or immutable, which can significantly alter the behavior of the batch utilisation (more details below).
Choosing depth
The minimum value for depth is 17, however a higher depth value is recommended for most use cases due to the mechanics of stamp batch utilisation. See the depths utilisation table to help decide which depth is best for your use case.
One notable aspect of batch utilisation is that the entire batch is considered fully utilised as soon as any one of its buckets are filled. This means that the actual amount of chunks storable by a batch is less than the nominal maximum amount.
See the postage stamp page for a more complete explanation of how batch utilisation works and a table with the specific amounts of data which can be safely uploaded for each depth value.
Choosing amount
The minimum amount value for purchasing stamps is required to be at least enough to pay for 24 hours of storage. To find this value multiply the lastPrice value from the postage stamp contract times 17280 (the number of blocks in 24 hours). You can also use the calculator below. This requirement is in place in order to prevent spamming the network.
The amount parameter determines how much xBZZ is assigned per chunk for a postage stamp batch. You can use the calculators below to find the appropriate amount value for your target duration of storage and can also preview the price. For more information see the postage stamp page where a more complete description is included.
Mutable or Immutable?
Depending on the use case, uploaders may desire to use mutable or immutable batches. The fundamental difference between immutable and mutable batches is that immutable batches become unusable once their capacity is filled, while for mutable batches, once their capacity is filled, they may continue to be used, however older chunks of data will be overwritten with the newer once over capacity. The default batch type is immutable. In order to set the batch type to mutable, the immutable header should be set to false. See this section on postage stamp batch utilisation to learn more about mutable vs immutable batches, and about which type may be right for your use case.
Calculators
The following postage batch calculators allow you to conveniently find the depth and amount values for a given storage duration and storage volume, or to find the storage duration and storage volume for a given depth and amount. The results will display the cost in xBZZ for the postage batch. The current pricing information is sourced from the Swarmscan API and will vary over time.
The 'effective volume' is the volume of data that can be safely stored for each batch depth, with a failure rate of less than 0.1%. The 'theoretical max volume' is significantly higher than the effective volume at lower depths, and the two values trend towards the same value at higher depths. Effective volumes are available for all depths from 17 to 41, and depend on the encryption and erasure coding settings selected. For example, at depth 17, the effective volume ranges from 13.17 kB (encrypted, paranoid) to 44.70 kB (unencrypted, no erasure coding). Learn more here.
Depth & Amount to Time & Volume Calculator
Time & Volume to Depth & Amount Calculator
The recommended depth in this calculator's results is the lowest depth value whose effective volume is greater than the entered volume.
Viewing Stamps
To check on your stamps, send a GET request to the stamp endpoint.
- API
- Swarm CLI
API
curl http://localhost:1633/stamps
{
"stamps": [
{
"batchID": "f4b9830676f4eeed4982c051934e64113dc348d7f5d2ab4398d371be0fbcdbf5",
"utilization": 0,
"usable": true,
"label": "",
"depth": 20,
"amount": "100000000",
"bucketDepth": 16,
"blockNumber": 30643611,
"immutableFlag": true,
"exists": true,
"batchTTL": 20588,
"expired": false
}
]
}
Swarm CLI
swarm-cli stamp list
Stamp ID: f4b9830676f4eeed4982c051934e64113dc348d7f5d2ab4398d371be0fbcdbf5
Usage: 0%
Remaining Capacity: 4.00 GB
TTL: 5 hours 42 minutes 18 seconds
Expires: 2023-10-26
It is not possible to reupload unencrypted content which was stamped using an expired postage stamp.