Dynamic object filed names serialization

This is a question from the Suinami Riders group (Telegram).

I’m having trouble with rpc.getDynamicFieldObject(parentId, fieldName) because I don’t know how to serialize dynamic field names.
Say I have a parent object which contains two dynamic field objects:

  • The name for the 1st one is “Early”, as a vector<u8>
  • The name for the 2nd one is “Early”, as a sui::string::String
    They look like this on-chain:
sui>-$ dynamic-field --json PARENT_OBJECT_ID
  "data": [
    { "name": "vector[69u8, 97u8, 114u8, 108u8, 121u8]", ... },
    { "name": "0x1::string::String {bytes: vector[69u8, 97u8, 114u8, 108u8, 121u8]}", ... }
  ], ...

Now I want to fetch these dynamic objects from JS:

// Doesn't work:
rpc.getDynamicFieldObject(PARENT_OBJECT_ID, 'Early');
// Works (1st object):
rpc.getDynamicFieldObject(PARENT_OBJECT_ID, 'vector[69u8, 97u8, 114u8, 108u8, 121u8]');
// Works (2nd object):
rpc.getDynamicFieldObject(PARENT_OBJECT_ID, '0x1::string::String {bytes: vector[69u8, 97u8, 114u8, 108u8, 121u8]}');

My question is, how can I transform the JS string “Early” into the correct format for dynamic field names so that rpc.getDynamicFieldObject() finds the objects?


Thanks for posting my question here. Just to be clear, rpc in the example above is an instance of JsonRpcProvider from @mysten/sui.js.

1 Like

Looks like this PR will solve it: