The manual operation (
RestoreFootprintOp) is, for the most part, no longer needed starting in Protocol 23, as archived entries included in a transaction’s restore list (usually populated during transaction simulation) are automatically restored when the InvokeHostFunctionOp executes. RestoreFootprintOp can be used in rare use cases described in this section.createRestorationFootprint used for manually creating a restoration footprint and restore archived data in a contract.
First let’s revisit how data is stored in a smart contract with the three different state archival types:
As seen above, all contract data is automatically archived when TTL reaches
0, except for Temporary entries, which are deleted permanently from the ledger.
Both types Instance and Persistent are suitable for storing data that cannot be easily recreated, with the nuance that Instance shares the same TTL as the contract instance while Persistent does not and, if the contract instance is not archived, Persistent data may be archived and need to be restored before invoking the contract.
For a detailed explanation of contract data archival, check out the State Archival section.
Code walkthrough
As we’re making use of Stellar SDK for JavaScriptjs-stellar-sdk, first we import the module.
Our function will require the following parameters:
account: The Stellar account from which the transaction will be sent.contractAddress: The address of the contract to be restored.fee: The fee for the transaction.dataKey: The key for the contract data to be restored.signer: The keypair that will sign the transaction.
contract: The contract address.key: The key for the contract data.durability: Specifies that the contract data is persistent - we assume it’sPersistent.
resources: Specifies the resources needed for the transaction.footprint: Defines which parts of the ledger will be read and written.instructions,diskReadBytes,writeBytes: Sets the resource limits (all set to 0 here).resourceFee: Sets the resource fee to 0 (placeholder).ext: Extension point for future use (set to 0).
readWrite.
The transaction can now be submitted to the Stellar (test) network & signed to restore the specified contract’s data.