Skip to content

Can't get object content as JSON #350

@Thoralf-M

Description

@Thoralf-M
use eyre::{OptionExt, Result};
use iota_graphql_client::Client;
use iota_types::ObjectId;

#[tokio::main]
async fn main() -> Result<()> {
    let client = Client::new_mainnet();

    let object_id =
        ObjectId::from_hex("0x8fc555a1a3844efcf89840bb367bba3347df88bd4779baa180e1afec508ad8ef")?;

    let obj = client
        .object(object_id, None)
        .await?
        .ok_or_eyre("missing object")?;
    println!("{obj:?}");

    Ok(())
}

we only get the content as bcs bytes:

Object { data: Struct(MoveStruct { type_: StructTag { address: Address("0xbf1e1f471d7f7b54e1c13ffbd0cb96d72b12c206cb27663bc130edaf45599b95"), module: Identifier("aylab_3"), name: Identifier("Aylab3NFT"), type_params: [] }, version: 238769137, contents: [143, 197, 85, 161, 163, 132, 78, 252, 248, 152, 64, 187, 54, 123, 186, 51, 71, 223, 136, 189, 71, 121, 186, 161, 128, 225, 175, 236, 80, 138, 216, 239, 7, 65, 121, 108, 97, 98, 32, 51, 11, 65, 121, 108, 97, 98, 32, 78, 70, 84, 32, 51, 58, 104, 116, 116, 112, 115, 58, 47, 47, 115, 116, 111, 114, 97, 103, 101, 46, 103, 111, 111, 103, 108, 101, 97, 112, 105, 115, 46, 99, 111, 109, 47, 103, 97, 109, 105, 102, 108, 121, 45, 110, 102, 116, 47, 97, 121, 108, 97, 98, 95, 110, 102, 116, 95, 51, 46, 112, 110, 103] }), owner: Address(Address("0x2b54d6486b50a606fadce0a5adcc97411cfe94ca7bbc2942c83baa35f63caefd")), previous_transaction: Digest("HL8h168Czzhj37QEH5SnviZJKuueEJUytF3C3Mb5J4ev"), storage_rebate: 1907600 }

one could deserialize the type with bcs and encode it to JSON, but the graphql API also supports returning the JSON directly which is easier:
https://graphql.mainnet.iota.cafe

{
  object(
    address: "0x8fc555a1a3844efcf89840bb367bba3347df88bd4779baa180e1afec508ad8ef"
  ) {
    asMoveObject {
      digest
      contents {
        json
      }
    }
  }
}
{
  "data": {
    "object": {
      "asMoveObject": {
        "digest": "9LRdJDYbkskR2kounb69MMrrXZnjGQvX78jbzeCEr8aU",
        "contents": {
          "json": {
            "id": "0x8fc555a1a3844efcf89840bb367bba3347df88bd4779baa180e1afec508ad8ef",
            "name": "Aylab 3",
            "description": "Aylab NFT 3",
            "url": {
              "url": "https://storage.googleapis.com/gamifly-nft/aylab_nft_3.png"
            }
          }
        }
      }
    }
  }
}

it should be also possible to get the content as JSON using the SDK

There exists

pub struct Object {
    pub as_move_object: Option<MoveObjectContents>,

but this seems to be not accessible/not the returned type

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions