Skip to main content
Version: 2.4.0

declareState

function declareState<T>(SmartContract: T, states: Record<string, FlexibleProvablePure<any>>): void

Defined in: lib/mina/v1/state.ts:176

declareState can be used in place of the @state decorator to declare on-chain state on a SmartContract. It should be placed after the class declaration. Here is an example of declaring a state property x of type Field.

class MyContract extends SmartContract {
x = State<Field>();
// ...
}
declareState(MyContract, { x: Field });

If you're using pure JS, it's not possible to use the built-in class field syntax, i.e. the following will not work:

// THIS IS WRONG IN JS!
class MyContract extends SmartContract {
x = State();
}
declareState(MyContract, { x: Field });

Instead, add a constructor where you assign the property:

class MyContract extends SmartContract {
constructor(x) {
super();
this.x = State();
}
}
declareState(MyContract, { x: Field });

Type Parameters

T extends typeof SmartContract

Parameters

SmartContract

T

states

Record<string, FlexibleProvablePure<any>>

Returns

void