Skip to main content
Version: 10.8.0

Class: CallData

Defined in: src/utils/calldata/index.ts:44

Constructors​

Constructor​

new CallData(abi, parsingStrategy?): CallData

Defined in: src/utils/calldata/index.ts:53

Parameters​

abi​

Abi

parsingStrategy?​

ParsingStrategy

Returns​

CallData

Properties​

abi​

abi: Abi

Defined in: src/utils/calldata/index.ts:45


parser​

parser: AbiParserInterface

Defined in: src/utils/calldata/index.ts:47


structs​

protected readonly structs: AbiStructs

Defined in: src/utils/calldata/index.ts:49


enums​

protected readonly enums: AbiEnums

Defined in: src/utils/calldata/index.ts:51

Methods​

compile()​

static compile(rawArgs): Calldata

Defined in: src/utils/calldata/index.ts:174

Compile contract callData without abi

Parameters​

rawArgs​

RawArgs

RawArgs representing cairo method arguments or string array of compiled data

Returns​

Calldata

Calldata


getAbiStruct()​

static getAbiStruct(abi): AbiStructs

Defined in: src/utils/calldata/index.ts:299

Helper to extract structs from abi

Parameters​

abi​

Abi

Abi

Returns​

AbiStructs

AbiStructs - structs from abi


getAbiEnum()​

static getAbiEnum(abi): AbiEnums

Defined in: src/utils/calldata/index.ts:316

Helper to extract enums from abi

Parameters​

abi​

Abi

Abi

Returns​

AbiEnums

AbiEnums - enums from abi


toCalldata()​

static toCalldata(rawCalldata?): Calldata

Defined in: src/utils/calldata/index.ts:335

Helper: Compile HexCalldata | RawCalldata | RawArgs

Parameters​

rawCalldata?​

RawArgs = []

HexCalldata | RawCalldata | RawArgs

Returns​

Calldata

Calldata


toHex()​

static toHex(raw?): HexCalldata

Defined in: src/utils/calldata/index.ts:344

Helper: Convert raw to HexCalldata

Parameters​

raw?​

RawArgs = []

HexCalldata | RawCalldata | RawArgs

Returns​

HexCalldata

HexCalldata


validate()​

validate(type, method, args?): void

Defined in: src/utils/calldata/index.ts:66

Validate arguments passed to the method as corresponding to the ones in the abi

Parameters​

type​

"DEPLOY" | "INVOKE" | "CALL"

ValidateType - type of the method

method​

string

string - name of the method

args?​

ArgsOrCalldata = []

ArgsOrCalldata - arguments that are passed to the method

Returns​

void


compile()​

compile(method, argsCalldata): Calldata

Defined in: src/utils/calldata/index.ts:119

Compile contract callData with abi Parse the calldata by using input fields from the abi for that method

Parameters​

method​

string

string - method name

argsCalldata​

RawArgs

RawArgs - arguments passed to the method. Can be an array of arguments (in the order of abi definition), or an object constructed in conformity with abi (in this case, the parameter can be in a wrong order).

Returns​

Calldata

Calldata - parsed arguments in format that contract is expecting

Example​

const calldata = myCallData.compile('constructor', ['0x34a', [1, 3n]]);
const calldata2 = myCallData.compile('constructor', { list: [1, 3n], balance: '0x34' }); // wrong order is valid

parse()​

parse(method, response): CallResult

Defined in: src/utils/calldata/index.ts:258

Parse elements of the response array and structuring them into response object

Parameters​

method​

string

string - method name

response​

string[]

string[] - response from the method

Returns​

CallResult

Result - parsed response corresponding to the abi


format()​

format(method, response, format): CallResult

Defined in: src/utils/calldata/index.ts:289

Format cairo method response data to native js values based on provided format schema

Parameters​

method​

string

string - cairo method name

response​

string[]

string[] - cairo method response

format​

object

object - formatter object schema

Returns​

CallResult

Result - parsed and formatted response object


decodeParameters()​

decodeParameters(typeCairo, response): AllowArray<CallResult>

Defined in: src/utils/calldata/index.ts:359

Parse the elements of a contract response and structure them into one or several Result. In Cairo 0, arrays are not supported.

Parameters​

typeCairo​

AllowArray<string>

string or string[] - Cairo type name, ex : "hello::hello::UserData"

response​

string[]

string[] - serialized data corresponding to typeCairo.

Returns​

AllowArray<CallResult>

Result or Result[] - parsed response corresponding to typeData.

Example​

const res2 = helloCallData.decodeParameters('hello::hello::UserData', ['0x123456', '0x1']);
result = { address: 1193046n, is_claimed: true };