A specialized Store class extending from @tanstack/store, designed for managing and interacting with application-level state on the Algorand blockchain.

The class provides methods to deploy, initialize, save, and retrieve application state stored in Algorand application storage boxes. It leverages the AlgorandClient for blockchain interactions and a Deployer for deploying and signing transactions.

import {Store} from '@awesome-algorand/store-kit'
const store = new Store({
algorand,
deployer,
options: {
foo: "bar",
baz: 123,
},
})

See the Store.constructor method for more information on how to instantiate the class.

Type Parameters

  • T

    The type of the state managed by the store. This may be omitted in favor of type inference.

Hierarchy

  • Store<T>
    • Store

Constructors

  • Constructs an instance of the class with the specified parameters.

    Type Parameters

    • T

      The type of the state managed by the store. This may be omitted in favor of type inference.

    Parameters

    Returns Store<T>

    Throws TypeError if algorand client not valid or a deployer is not defined.

    // Import the AlgorandClient
    import {AlgorandClient} from "@algorandfoundation/algokit-utils";
    // Import the Store class
    import {Store} from "./src";
    const algorand = AlgorandClient.fromEnvironment()
    const deployer = await algorand.account.fromEnvironment('DEPLOYER')
    const store = new Store({
    algorand,
    deployer,
    options: {
    foo: "bar",
    baz: 123,
    },
    })

Properties

algorand: AlgorandClient

Represents an instance of AlgorandClient, which provides mechanisms to interact with the Algorand blockchain network.

The algorand variable can be used to perform various operations such as querying blockchain data, submitting transactions, and interacting with Algorand smart contracts.

It acts as an interface to communicate with the Algorand network through methods exposed by the AlgorandClient.

client?: LodashClient

Experimental: On-chain client for the Lodash application.

deployer: Deployer

Represents a smart contract wallet capable of signing transactions. A Deployer is critical for managing interactions with Algorand smart contracts. It facilitates operations such as deploying and interacting with applications by ensuring all transactions are signed appropriately. See AppDeployer for more information

factory: LodashFactory

Experimental: Factory for the Lodash application.

listeners: Set<Listener<T>>
options?: StoreOptions<T, (cb: T) => T>
prevState: T
setState: (updater: (cb: T) => T) => void
state: T
subscribe: (listener: Listener<T>) => () => void

Methods

  • Assembles and retrieves data stored in the storage boxes of an application, decodes the content, and formats it into a structured object.

    Returns Promise<T>

    Returns a Promise that resolves to an object of type T, containing the decoded and processed data from the application storage boxes.

    Throws an error if the client is undefined, indicating that initialization has not been completed.

  • Initializes the instance by deploying the required application and setting up necessary configurations. Throws an error if already initialized. Deploys the application using the provided factory and performs payment if the result operation requires it.

    Parameters

    • name: string

      The name of the application to deploy.

    Returns Promise<void>

    A promise that resolves when the initialization process is complete.

    Throws an error if the method is called more than once.

  • Saves the current state to the network. This method ensures that the app is initialized and a deployer is provided before attempting to save. It synchronizes the state by mapping paths to their respective values and storing them on-chain.

    Returns Promise<void>

    Resolves when the state has been successfully saved to the network.

    Throws an error if the app has not been initialized with a client or if a deployer is not provided.

    // Import a custom Store instance
    import {exampleStore} from "./exampleStore"
    // Save the state to the network
    await exampleStore.save()

    Deployer can be passed as an argument to the save method

    // Import a custom Store instance
    import {exampleStore} from "./exampleStore"
    // Define a deployer
    const deployer = await algorand.account.fromMnemonic("example deployer mnemonic")
    // Save the state to the network
    await exampleStore.save(deployer)
  • Returns (undefined | string)[][]

  • Returns (undefined | string)[]