Skip to content

Commit e18aa3e

Browse files
authored
feat(ink): add docs for ink attributes (#54)
1 parent 0894113 commit e18aa3e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/pages/ink.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
:::

0 commit comments

Comments
 (0)