Post
Share your knowledge.
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
Answers
3Apparently, 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.
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.
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.
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.