Skip to content

Shared State

Overview

Shared state allows for Aleo state (ie Records) to be owned and viewable by multiple parties — very similar to a multisig. For example, you could play a private game of cards between two users. The Puzzle SDK provides some shared state primitives to allow developers to use multiparty shared state.

An Example

You can check out the “Where’s Alex?” repo here to see an example of shared state in action. In Where’s Alex, shared state is used to lock up the wagers for each instance of the game.

Shared State in the SDK

There are two main functions the SDK provides for shared state: createSharedState and importSharedState. These functions are used by multiple parties — Alice and Bob, for example — to share private state with each other. These two functions create and import an account that can be used by both parties to share private state. The seed of the account needs to be passed onchain between users.

createSharedState

To begin a shared state session between Alice and Bob, the application must call createSharedState. This function creates a shared state account within Alice’s wallet (assuming Alice is the one calling the function). It returns the private key seed and address if successful or an error if unsuccessful.

See here for more details.

importSharedState

After a shared state account has been created, it can then be imported by another user. For example, once Bob has connected his account, the application can call importSharedState with the shared seed to import the account to Bob’s wallet.

See here for more details.