Move.

帖子

分享您的知识。

Dominikus .
Jan 12, 2025
专家问答

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
分享
评论
.

答案

2
Theoremus.
Jan 12 2025, 15:19

虽然 Sui 智能合约无法通过 ID 直接访问合约中的对象,但你可以通过使用客户端库从区块链中获取所需的数据,然后将其作为输入提供给智能合约函数来解决这个问题. 这包括使用Sui的API或SDK与区块链进行交互并在调用智能合约之前检索必要的对象. 为了应对此类场景,开发人员通常使用Sui客户端或相关API在外部与区块链进行交互. 这些工具可以根据 ID 查询对象,然后便于将这些对象作为所需的输入传输到智能合约的函数中.

1
最佳答案
评论
.
Ramirez.
Jan 12 2025, 23:21

不幸的是,在 Sui 智能合约中,不可能仅使用其 ID 直接获取对象. 这是因为Sui上的智能合约无法像以太坊智能合约那样直接访问全球存储. 在 Sui 上,你需要从外部系统(例如客户端应用程序)获取对象,然后将其作为参数传递给智能合约方法.

1
评论
.

你知道答案吗?

请登录并分享。

Move is an executable bytecode language used to implement custom transactions and smart contracts.

148帖子231答案
Sui.X.Peera.

赚取你的 1000 Sui 份额

获取声誉积分,并因帮助 Sui 社区成长而获得奖励。

奖励活动七月