File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -253,3 +253,37 @@ if (response.success && response.value) {
253253 console .log (" error" , response .value )
254254}
255255```
256+
257+ ### Attributes
258+
259+ Ink! adds some attributes to some of the messages or constructors to indicate various features:
260+
261+ - ` default ` : Whether a message or constructor should be treated as the default.
262+ - ` payable ` : Whether a message or constructor accepts a ` value ` parameter which will transfer tokens from the origin signer to the contract's address.
263+ - ` mutates ` : Whether a message performs a change to the storage.
264+
265+ The ink client exposes these properties on the message and constructor objects:
266+
267+ ``` ts
268+ const psp22Constructor = psp22Client .constructor (" new" )
269+ console .log (psp22Constructor .attributes )
270+
271+ const increaseAllowance = psp22Client .message (" PSP22::increase_allowance" )
272+ console .log (increaseAllowance .attributes )
273+ ```
274+
275+ Additionally, if the contract does have a "default" message or constructor specified, then the id of that can also be found in the client itself:
276+
277+ ``` ts
278+ const defaultConstructor = psp22Client .defaultConstructor
279+ ? psp22Client .message (psp22Client .defaultConstructor )
280+ : null
281+
282+ const defaultMessage = psp22Client .defaultMessage
283+ ? psp22Client .message (psp22Client .defaultMessage )
284+ : null
285+ ```
286+
287+ ::: note
288+ For better typescript support, if you're working with just one contract that has a defaultConstructor, then the types will already be non-nullable. In that case you shouldn't need the nullable ternary.
289+ :::
You can’t perform that action at this time.
0 commit comments