Post
Share your knowledge.
How can I store global variables in Move smart contracts effectively?
How can global variables be stored in Move smart contracts effectively?
- Move CLI
- Move
Answers
3In Move, there is no concept of traditional global storage. Instead, you can store global data using a shared object, which lets you encapsulate data that can be accessed across different modules or functions. This approach helps manage data similarly to global variables in other programming environments .
The shared.move
file in the Tic Tac Toe example provided by Sui showcases how a Game
object is shared so both players can interact with it. The use of shared objects in this context allows global-like data sharing across different participants .
An example of using a shared object to store global data in a Move smart contract is demonstrated on the Sui documentation: transfer::share_object(Object { id: object::new(ctx), ... })
. This method involves creating an object that has the key
ability, allowing it to be part of Sui's global object pool .
Do you know the answer?
Please log in and share it.
Move is an executable bytecode language used to implement custom transactions and smart contracts.