Move.

Post

Share your knowledge.

Dominikus .
Jan 12, 2025
Expert Q&A

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
1
2
Share
Comments
.

Answers

2
Theoremus.
Jan 12 2025, 15:19

While 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.

1
Best Answer
Comments
.
Ramirez.
Jan 12 2025, 23:21

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.

1
Comments
.

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.

148Posts231Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

Gain Reputation Points & Get Rewards for Helping the Sui Community Grow.

Reward CampaignJune
We use cookies to ensure you get the best experience on our website.
More info