Skip to content

sui的nodejs前端如何遍历容器内容,vector,table,bag? #274

Answered by qiwihui
baidang201 asked this question in Q&A
Discussion options

You must be logged in to vote

首先你要将这几个容器存放在 Sui 对象中,才能被 Sui 区块链索引到。我以我在 foxgame-contracts 这个项目中的 FoCRegistry 这个对象为例(省略了其他非必要的字段):

    struct Global has key {
        id: UID,
        foc_registry: FoCRegistry,
    }

    struct FoCRegistry has key, store {
        id: UID,
        foc_hash: vector<u8>,
        types: Table<ID, bool>,
        trait_data: Table<u8, Table<u8, Trait>>,
    }

其中包含了 vector 类型的 foc_hashtable 类型的 types,我们会用到 Sui RPC 中的 sui_getObjectsui_getObjectsOwnedByObject,和 sui_getDynamicFields。合约部署之后,可以找到 Global 对象 ID 为 0xc2461548818b1db84824dffffb8daebfb984e612,调用 sui_getObject 可以得到对象 Global 的信息:

{
    "jsonrpc": "2.0",
    "result": {
        "status": "Exists",
        "details": {
            "data"

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by baidang201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants