Move.

Post

Share your knowledge.

Britain.
Apr 07, 2025
Expert Q&A

How to fetch values from ObjectTable using Dynamic Fields?

I'm trying to fetch values from an ObjectTable using Dynamic Fields from the frontend, but I'm encountering an error with dynamicFieldObject. The error says Unexpected arg String("gms") for the expected type Struct(MoveStructLayout...). How can I get the correct type for the value and avoid this error?

  • Move CLI
  • Move
0
3
Share
Comments
.

Answers

3
Theoremus.
Apr 7 2025, 18:58

Apparently, the original poster managed to resolve their issue by utilizing the example provided. If you follow the example closely and ensure the IDs and types correctly correspond to your data, it should work perfectly.

0
Comments
.
YJS.
YJS94
Apr 8 2025, 07:36

You can fetch the values from an ObjectTable using the following code example:

const getTable = async () => {
  const res = await client.getDynamicFields({
    parentId: "YOUR_PARENT_ID_HERE",
  });

  res.data.forEach(async (df) => {
    console.log(df.name, df.objectId);
    const res = await client.getDynamicFieldObject({
      parentId: "YOUR_PARENT_ID_HERE",
      name: df.name,
    });

    let field = res.data?.content?.fields;

    console.log("DF read", field.name);
  });
};

Replacing YOUR_PARENT_ID_HERE with your actual parent ID should help achieve your goal.

0
Comments
.
farshad.
Apr 8 2025, 12:00

If you are facing an error with dynamicFieldObject, ensure the type and value match what's expected. You may need to verify the structure you're passing in name matches the expected layout. Additionally, using getObject should retrieve the parent object details which might include the necessary ID, but ensure it exists and is referenced properly.

0
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