Skip to main content
Version: 11.x

Class: CallData

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

Constructors​

Constructor​

new CallData(abi, parsingStrategy?): CallData

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

Parameters​

abi​

Abi

parsingStrategy?​

CairoTypeStrategy | ParsingStrategy

Returns​

CallData

Properties​

abi​

abi: Abi

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


parser​

parser: AbiParserInterface

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

Methods​

compile()​

static compile(rawArgs): Calldata

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

Compile contract callData without abi

An instance of a Cairo type class — CairoByteArray, CairoBytes31, CairoUint256, … — is serialized by that class, so it yields the same felts here as it would through an abi. Any other object is walked field by field, which is what makes a plain { low, high } and the object of byteArrayFromString work just as well.

A string[] value is always read as a Cairo array and gains a length in front of it, an already compiled one included : pass the instance itself rather than its toApiRequest().

Parameters​

rawArgs​

RawArgs

RawArgs representing cairo method arguments or string array of compiled data

Returns​

Calldata

Calldata

Example​

const result = CallData.compile({ text: CairoByteArray.fromText('12345') });
// result = ["0", "211295614005", "5"]
const result2 = CallData.compile({ text: CairoByteArray.fromText('12345').toApiRequest() });
// result2 = ["3", "0", "211295614005", "5"] the three felts, behind an array length

getAbiStruct()​

static getAbiStruct(abi): AbiStructs

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

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:372

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:381

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:390

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:92

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:154

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:327

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:353

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:405

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 }