Post
Share your knowledge.
How to fetch objects by ID in a Sui smart contract?
I've been working on a Sui smart contract and want to understand how to fetch an object by its ID from within the smart contract itself. From what I've gathered, it seems like smart contracts on Sui don't have the direct capability like in Ethereum's Solidity to access storage and retrieve objects by their IDs. I'm looking for some guidance on whether this is possible directly within the smart contract or if I need to approach it differently.
- Move CLI
- Move
Answers
2While Sui smart contracts cannot directly access objects by ID within the contract, you can work around this by using client-side libraries to fetch the needed data from the blockchain and then provide it as input to the smart contract functions. This involves using Sui's API or SDK to interact with the blockchain and retrieve the necessary objects before invoking the smart contract. To deal with such scenarios, developers typically use the Sui client or related APIs to interact with the blockchain externally. These tools can query objects based on IDs and then facilitate the transmission of those objects into the smart contract's functions as required inputs.
Unfortunately, within a Sui smart contract, it's not possible to directly fetch an object using just its ID. This is because smart contracts on Sui do not have direct access to global storage in the way that Ethereum smart contracts do. On Sui, you'll need to fetch the object from an external system, such as a client-side application, and then pass it as an argument to a smart contract method.
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.

- ... SUIderiss+5
- ... SUIRamirez+5
- ... SUIElvin CLONE +5
- ... SUI
- ... SUI
- ... SUI
- ... SUIBritain+2