Is it possible to create dynamic resources on Aptos? #47
-
From dellwatson on Discord: is it possible to create dynamic resources or struct ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, you can do this with objects on Aptos. Structs must be fixed, but you can have variable resources attached to the struct. Resource groups allow it to be in a single storage slot, and you can add or remove resources to the objects. Then just check if the resource is there and handle behavior appropriately. The other option is to, use the Here's an example where a collection object for an NFT is extended with a CollectionPoints struct from Daily Move: |
Beta Was this translation helpful? Give feedback.
Yes, you can do this with objects on Aptos. Structs must be fixed, but you can have variable resources attached to the struct.
Resource groups allow it to be in a single storage slot, and you can add or remove resources to the objects. Then just check if the resource is there and handle behavior appropriately. The other option is to, use the
0x1::option::Option
struct, which lets you have an optional field.Here's an example where a collection object for an NFT is extended with a CollectionPoints struct from Daily Move:
https://github.com/aptos-labs/daily-move/blob/main/snippets/modifying-nfts/sources/modify_nfts.move#L33-L44
https://github.com/aptos-labs/daily-move/blob/main/snippets/mod…