Contract Storage API's currently only available for ink! v5 and v6! if you want to use storage API for ink! v4.
Contract Storage API provides efficient access to smart contract storage data. This API allows developers to read contract storage without executing contract methods, enabling efficient data retrieval.
Dedot provides two distinct approaches to accessing contract storage, each optimized for different use cases
RootStorage: Fetch and decode the entire root storage of the contract including API to retrieve data from lazy storage/fields like , , . For lazy storage, you will have to make a separate call to fetch the data since they're using a different storage layout.
LazyStorage (or ): Provide access to only lazy/non-packed storage/fields like , , if you just want to fetch data from these fields separately without having to fetch the whole root storage first.
Root Storage
Example Root Storage for Flipper contract
import { FlipperContractApi, Flipper } from './flipper/index.ts'; // Generated types for flipper contract
const contract = new Contract<FlipperContractApi>(api, metadata, contractAddress);
/**
* Generated RootStorage type for Flipper contract
*
* interface Flipper {
* value: boolean
* }
*/
const root: Flipper = await contract.storage.root();
const value: boolean = root.value;