You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/pages/types.mdx
+36-1
Original file line number
Diff line number
Diff line change
@@ -33,10 +33,45 @@ Enums in the chain are represented as `{ type: string, value: T }`. As many of t
33
33
34
34
First of all, the Enums that are widely used across multiple chains are in a directory of well-known types, and they are represented with a descriptive name. A few examples: `MultiAddress`, `BalanceStatus`, `IdentityJudgement`, and many of the XCM pallet types: `XcmV3Junction`, `XcmV3MultiassetFungibility`, etc.
35
35
36
-
For these types, you can import them directly from the generated code and use them by calling their type:
36
+
For these types, you can import them directly from the generated code and use them by calling their type. The call signature shown by an IDE will tell you exactly which enum types you should use to write your value. The following video shows how it might look like:
37
37
38
38
<videosrc="enums.mp4"controls />
39
39
40
+
The enums that are not well-known types, they are anonymous. In that case, you will find something like the following in the call signature:
41
+
42
+
```ts
43
+
(value:IEnum<{
44
+
transfer_allow_death: {
45
+
dest:MultiAddress;
46
+
value:bigint;
47
+
};
48
+
force_transfer: {
49
+
dest:MultiAddress;
50
+
value:bigint;
51
+
source:MultiAddress;
52
+
};
53
+
...4more ...;
54
+
force_set_balance: {
55
+
...;
56
+
};
57
+
}>) =>PolkadotRuntimeRuntimeCall
58
+
```
59
+
60
+
This indicates that the parameter value is an enum, whose key will be either one of the keys of the object type (i.e. `transfer_allow_death`, `force_transfer`, ..., `force_set_balance`), and the type will be the value for that particular key.
61
+
62
+
For these cases, you should use the function `Enum(type, value)`, imported from `@polkadot-api/client`. This has full type inference support, and creates an Enum object that can be used as a parameter of a call:
When reading from Enums, these are objects with `{ type: string, value: unknown }` with discriminated types based on the `type` (so if you do `switch (enum.type) {` you will have the correct value for the `type`).
74
+
40
75
## Binary
41
76
42
77
Any array of u8's is represented as Binary. This is a utility type that has a few functions to easily create binary data:
0 commit comments