Class: CallData
Constructors
constructor
• new CallData(abi, parsingStrategy?): CallData
Parameters
| Name | Type |
|---|---|
abi | Abi |
parsingStrategy? | ParsingStrategy |
Returns
Defined in
src/utils/calldata/index.ts:53
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
▸ compile(rawArgs): Calldata
Compile contract callData without abi
Parameters
| Name | Type | Description |
|---|---|---|
rawArgs | RawArgs | RawArgs representing cairo method arguments or string array of compiled data |
Returns
Calldata
Defined in
src/utils/calldata/index.ts:174
getAbiStruct
▸ getAbiStruct(abi): AbiStructs
Helper to extract structs from abi
Parameters
| Name | Type | Description |
|---|---|---|
abi | Abi | Abi |
Returns
AbiStructs - structs from abi
Defined in
src/utils/calldata/index.ts:299
getAbiEnum
▸ getAbiEnum(abi): AbiEnums
Helper to extract enums from abi
Parameters
| Name | Type | Description |
|---|---|---|
abi | Abi | Abi |
Returns
AbiEnums - enums from abi
Defined in
src/utils/calldata/index.ts:316
toCalldata
▸ toCalldata(rawCalldata?): Calldata
Helper: Compile HexCalldata | RawCalldata | RawArgs
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
rawCalldata | RawArgs | [] | HexCalldata | RawCalldata | RawArgs |
Returns
Calldata
Defined in
src/utils/calldata/index.ts:335
toHex
▸ toHex(raw?): HexCalldata
Helper: Convert raw to HexCalldata
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
raw | RawArgs | [] | HexCalldata | RawCalldata | RawArgs |
Returns
HexCalldata
Defined in
src/utils/calldata/index.ts:344
validate
▸ validate(type, method, args?): void
Validate arguments passed to the method as corresponding to the ones in the abi
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
type | "DEPLOY" | "INVOKE" | "CALL" | undefined | ValidateType - type of the method |
method | string | undefined | string - name of the method |
args | ArgsOrCalldata | [] | ArgsOrCalldata - arguments that are passed to the method |
Returns
void
Defined in
src/utils/calldata/index.ts:66
compile
▸ compile(method, argsCalldata): Calldata
Compile contract callData with abi Parse the calldata by using input fields from the abi for that method
Parameters
| Name | Type | Description |
|---|---|---|
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 - 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
Defined in
src/utils/calldata/index.ts:119
parse
▸ parse(method, response): CallResult
Parse elements of the response array and structuring them into response object
Parameters
| Name | Type | Description |
|---|---|---|
method | string | string - method name |
response | string[] | string[] - response from the method |
Returns
Result - parsed response corresponding to the abi
Defined in
src/utils/calldata/index.ts:258
format
▸ format(method, response, format): CallResult
Format cairo method response data to native js values based on provided format schema
Parameters
| Name | Type | Description |
|---|---|---|
method | string | string - cairo method name |
response | string[] | string[] - cairo method response |
format | object | object - formatter object schema |
Returns
Result - parsed and formatted response object
Defined in
src/utils/calldata/index.ts:289
decodeParameters
▸ decodeParameters(typeCairo, response): AllowArray<CallResult>
Parse the elements of a contract response and structure them into one or several Result. In Cairo 0, arrays are not supported.
Parameters
| Name | Type | Description |
|---|---|---|
typeCairo | AllowArray<string> | string or string[] - Cairo type name, ex : "hello::hello::UserData" |
response | string[] | string[] - serialized data corresponding to typeCairo. |
Returns
Result or Result[] - parsed response corresponding to typeData.
Example
const res2 = helloCallData.decodeParameters('hello::hello::UserData', ['0x123456', '0x1']);
result = { address: 1193046n, is_claimed: true };