# How to auto resolve ipld refs by dag.get

**URL:** <https://discuss.ipfs.tech/t/how-to-auto-resolve-ipld-refs-by-dag-get/5377>\
**Category:** js-ipfs\
**Created:** [May 10, 2019, 12:15am UTC](https://discuss.ipfs.tech/t/how-to-auto-resolve-ipld-refs-by-dag-get/5377 "2019-05-10T00:15:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonybang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/jonybang/32/7876_2.png) [@Jonybang](https://discuss.ipfs.tech/u/Jonybang)\
**Post date:** [May 10, 2019, 12:15am UTC](https://discuss.ipfs.tech/t/how-to-auto-resolve-ipld-refs-by-dag-get/5377/1 "2019-05-10T00:15:03Z")

</div>

I’ve seen many cases where code like this works:

```auto
const obj = { simple: 'object' };
const dagParams = { format: 'dag-cbor', hashAlg: 'sha3-512' };
const cid = await ipfs.dag.put(obj, dagParams);
const cidString = cid.toBaseEncodedString();

const obj2 = {
  complex: 'object',
  link: {
    '/' : cidString
  }
}
const cid2 = await ipfs.dag.put(obj2, dagParams)
const cid2String = cid2.toBaseEncodedString();

const obj2 = await ipfs.dag.get(cid2String)
console.log(obj2.value)
// {
// complex: "object",
// link: {
// "simple" : "object"
// }
// }

```

But now, after many great updates - i got something like this in response:

```auto
{ complex: "object",
     link:
      CID {
        codec: 'dag-cbor',
        version: 1,
        multihash:
         <Buffer 12 20 14 da 02 e8 8d 43 e5 a5 c1 b7 c1 af 93 a4 5b 53 7c 3e 4c e2 87 03 a3 1c 29 04 59 6e b6 f1 90 65> } }

```

Can anybody help me with 2 cases:

1. Auto resolve CID objects that points to ipld data.
2. Convert all CID objects in structure toBaseEncodedString

I tried to work with js-ipfs@0.35.0 and ipfs-http-client@30.1.4, but result the same.

Whether there is a some callback that i can use for resolve or convert to base encoded string?

---

<div class="post-metadata">

**Author:** ![molly](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/molly/32/1834_2.png) [@molly](https://discuss.ipfs.tech/u/molly)\
**Post date:** [May 11, 2019, 12:22am UTC](https://discuss.ipfs.tech/t/how-to-auto-resolve-ipld-refs-by-dag-get/5377/2 "2019-05-11T00:22:43Z")

</div>

@lidel - this smells like a potential CID versioning issue. Any suggestions for Jonybang?

---

<div class="post-metadata">

**Author:** ![alanshaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/alanshaw/32/8381_2.png) [@alanshaw](https://discuss.ipfs.tech/u/alanshaw)\
**Post date:** [May 12, 2019, 6:12am UTC](https://discuss.ipfs.tech/t/how-to-auto-resolve-ipld-refs-by-dag-get/5377/3 "2019-05-12T06:12:08Z")

</div>

I don’t believe there’s a way to get back an object with all CID links resolved.

You can always `await ipfs.dag.get(cid2String, 'link')` to get back the linked `obj`.

There is also `ipfs.dag.tree`, which will give you back all the travserable paths in an object and you can detect if something is a CID by using `CID.isCID(obj2.link)` for example.

See [https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/DAG.md](https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/DAG.md) for more info.

---

<div class="post-metadata">

**Author:** ![Jonybang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/jonybang/32/7876_2.png) [@Jonybang](https://discuss.ipfs.tech/u/Jonybang)\
**Post date:** [May 13, 2019, 2:54pm UTC](https://discuss.ipfs.tech/t/how-to-auto-resolve-ipld-refs-by-dag-get/5377/4 "2019-05-13T14:54:16Z")

</div>

Okay, thank you. But in some of previous versions - did it work? It was refused due to inefficiency or security concerns?  
And what about loadFormat function in ipld config, may it used for resolve or convert to string cid properties?

---

<div class="post-metadata">

**Author:** ![alanshaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/alanshaw/32/8381_2.png) [@alanshaw](https://discuss.ipfs.tech/u/alanshaw)\
**Post date:** [May 13, 2019, 3:24pm UTC](https://discuss.ipfs.tech/t/how-to-auto-resolve-ipld-refs-by-dag-get/5377/5 "2019-05-13T15:24:32Z")

</div>

> But in some of previous versions - did it work? It was refused due to inefficiency or security concerns?

No, as far as I’m aware that’s never been a feature.

> And what about loadFormat function in ipld config, may it used for resolve or convert to string cid properties?

`loadFormat` is for loading a resolver for a particular IPLD format, allowing IPFS to read git, ethereum, zcash or other data.

see [GitHub - ipld/js-ipld: The JavaScript Implementation of IPLD](https://github.com/ipld/js-ipld#optionsloadformatcodec)

---

<div class="post-metadata">

**Author:** ![Jonybang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/jonybang/32/7876_2.png) [@Jonybang](https://discuss.ipfs.tech/u/Jonybang)\
**Post date:** [May 13, 2019, 3:39pm UTC](https://discuss.ipfs.tech/t/how-to-auto-resolve-ipld-refs-by-dag-get/5377/6 "2019-05-13T15:39:55Z")

</div>

So i could to make my own resolver for ipld for convert cid objects to strings or resolve them to objects with data?
