Skip to main content
Version: 11.x

Function: structStrategy()

structStrategy(structs): CairoTypeStrategy

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

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

A struct is the one Cairo type with no shape to recognize : its abi type is the name the contract chose, which looks like any other. So it cannot be a dynamic selector — one that matched by name would have to know every name in advance, and one that matched anything would shadow every other type. Instead each struct becomes an ordinary entry keyed by its own name, which is what a lookup tries first.

That is what the second argument of every composite is for : the strategies are searched in order, so a call passes [cairoTypeStrategy, structStrategy(structs)] and gets the language's types from the first and the contract's from the second.

Parameters

structs

AbiStruct[]

the struct definitions an abi declares

Returns

CairoTypeStrategy

a strategy carrying one entry per struct

Example

const point: AbiStruct = {
type: 'struct',
name: 'test::Point',
members: [
{ name: 'x', type: 'core::integer::u8' },
{ name: 'y', type: 'core::integer::u32' },
],
};
const strategies = [cairoTypeStrategy, structStrategy([point])];
const felts = strategies[1].constructors['test::Point']({ x: 1, y: 2 }, strategies)
.toApiRequest();
// felts = ["1", "2"]