Global states in Aptos smart contracts #429
-
Discord user IDenderwiggins Describe your question in detail.Hi, I am new to Aptos, and trying to learn common practices and patterns. I understand that the states here are stored as Resources in Accounts with "key" keyword. But how would one go about storing global states? e.g. If I am building lend/borrow platform - the liquidation factors, and oracle data for an asset is global state for the contract, and is not tied to an Account. Where would I store that? Are there any examples where I see global/account level states? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
aptos has objects, which are the common pattern for storing state which is not attached to an account aptos has "named objects" with deterministic mapping to address which can be used as global singletons, "normal objects" have a random address and can be used to create any number of objects the module is responsible for managing access control to state stored in objects you store references to objects with there's some example of how to use objects here: https://aptos.dev/en/build/smart-contracts/objects |
Beta Was this translation helpful? Give feedback.
aptos has objects, which are the common pattern for storing state which is not attached to an account
aptos has "named objects" with deterministic mapping to address which can be used as global singletons, "normal objects" have a random address and can be used to create any number of objects
the module is responsible for managing access control to state stored in objects
you store references to objects with
Object<MyType>
there's some example of how to use objects here: https://aptos.dev/en/build/smart-contracts/objects