Skip to main content
Version: 11.x

Function: enumStrategy()

enumStrategy(enums): CairoTypeStrategy

Defined in: src/utils/calldata/parser/cairoTypeStrategy.ts:369

The strategy for the custom enums an abi declares, to be used beside cairoTypeStrategy.

Built exactly like structStrategy, and for the same reason : a custom enum's abi type is the name the contract chose, so it is keyed by that name rather than recognized by a pattern.

Its constructors forward the variant, which for an enum is the index of the active branch — the one thing a raw value cannot say about itself.

Parameters

enums

AbiEnum[]

the enum definitions an abi declares

Returns

CairoTypeStrategy

a strategy carrying one entry per enum

Example

const abiEnum: AbiEnum = {
type: 'enum',
name: 'test::MyEnum',
variants: [
{ name: 'Empty', type: '()' },
{ name: 'Number', type: 'core::integer::u8' },
],
};
const strategies = [cairoTypeStrategy, enumStrategy([abiEnum])];
const felts = strategies[1].constructors['test::MyEnum'](7, strategies, 'test::MyEnum', 1)
.toApiRequest();
// felts = ["1", "7"]