Choose the storage context of a Starknet dispatcher call

A class hash and a contract address identify different things in Starknet. Choosing a library dispatcher to reuse code can make a function read or write the calling contract’s storage.

Identify which instance owns the state

Suppose A wants B’s recorded owner. Build the contract dispatcher for B’s deployed address and invoke the getter. Calling equivalent library code by class hash executes in A’s context and can read A’s storage layout instead.

contract dispatcher → target address B → storage of B
library dispatcher  → class hash H     → storage context of caller A

The two calls may both succeed and return plausible addresses. Test with A and B configured with deliberately different owners. Check the output against the expected instance rather than treating a successful call as proof of correct routing.

Constrain library code selection

Code running in the caller’s context can modify that caller’s state. Authenticate any configurable class hash and review storage compatibility before library dispatch. A class declaration alone does not establish that the code is suitable for the caller. starknet.io The Cairo Programming Language