> ## Documentation Index
> Fetch the complete documentation index at: https://stackrlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# State Variables

> Defining Custom State

### State Variable

Stackr allows rollupors to define their own custom state almost completely unrestricted in terms of what they can do with it

This is done by defining a `StateVariable` and providing relevant types.

```ts theme={null}
export type StateVariable = <YOUR_STATE_OBJECT>;
```

this could be as basic as a boolean or a single integer

<CodeGroup>
  ```ts boolean theme={null}
  export type StateVariable = boolean;
  ```

  ```ts number theme={null}
  export type StateVariable = number;
  ```
</CodeGroup>

or as complex as a full object with multiple properties and methods.

<CodeGroup>
  ```ts account theme={null}
  export type StateVariable = {
    address: string;
    balance: number;
    nonce: number;
  }[];
  ```

  ```ts dex theme={null}
  export type StateVariable = {
    orders: {
      id: string;
      maker: string;
      taker: string;
      makerAmount: number;
      takerAmount: number;
      filled: number;
    }[];
    trades: {
      id: string;
      maker: string;
      taker: string;
      makerAmount: number;
      takerAmount: number;
      filled: number;
    }[];
  };
  ```
</CodeGroup>

You can also rename the state variable to something more meaningful to your rollup.

```ts theme={null}
export type totalRollupSDKsThatAllowYouToBuildMicroRollups = 1;
```

But hey, that's a constant 😉

### State Transport

Once you have defined your state variable, you need to define how it is transported around.

StateTransport is just a wrapper around your state variable that allows you to define how it is transported around.
It also helps in defining how it is stored and how the state root is calculated.

This transport can also be whatever you want it to be.

<CodeGroup>
  ```ts basic theme={null}
  interface StateTransport {
    currentCount: StateVariable;
  }
  ```

  ```ts complex theme={null}
  import MerkleTree from "merkletreejs";

  class MerkleTreeTransport {
    public merkleTree: MerkleTree;
    public leaves: Accounts[];

    constructor(leaves: Accounts[]) {
      this.merkleTree = this.createTree(leaves);
      this.leaves = leaves;
    }

    createTree(leaves: Accounts[]) {
      const hashedLeaves = leaves.map((leaf: Accounts) => {
        return ethers.solidityPackedKeccak256(
          ["address", "uint"],
          [leaf.address, leaf.balance]
        );
      });
      return new MerkleTree(hashedLeaves);
    }
  }
  ```
</CodeGroup>

MerkleTree state is considered the most common state transport but Stackr allows you to define any crazy ideas that helps move state in most efficient format.
