# Fetch data from IPFS URI

* In smart contracts, some methods return a ***URI*** pointing to ***IPFS***.
* To fetch data from this URI we need first to register an [oracle](https://hyperdapp.gitbook.io/code-editor/guides/oracle-and-http-call):

```
oracle(ipfs, r, 'hyperdapp.mypinata.cloud/ipfs/').
```

* Then, we need to extract the ***CID*** from the ***IPFS URI.*** The URI root is what comes before the CID. For example, `https://ipfs.io/ipfs/`

```
// SYNTAX
extract_cid([URI, CID]) :-
  atom_chars(URI, S0),
  append(URI_ROOT, S1, S0),
  append(S2, "", S1),
  atom_chars(CID, S2).
  
// EXAMPLE
extract_cid([URI, CID]) :-
  atom_chars(URI, S0),
  append(https://ipfs.io/ipfs/, S1, S0),
  append(S2, "", S1),
  atom_chars(CID, S2).
```

* Finally, we can [prompt](https://hyperdapp.gitbook.io/code-editor/guides/prompt) the data returned from IPFS:

```
prompt :-
  call_fn(hyperdapp, tokenURI('55'),  [URI]),
  extract_cid([URI, CID]),
  get_http(ipfs, CID, { 
    name: Name, 
    description: Description,
    image: Image
  }),
  show [ 
    text('Name: ', Name),
    text('Description: ', Description),
    image(Image)
  ].
```

* We call the ***tokenURI*** method from the smart contract.
* We extract the ***CID*** from the URI.
* We use the ***get\_http()*** predicate on the ***ipfs*** [oracle](https://hyperdapp.gitbook.io/code-editor/guides/oracle-and-http-call). The output can be a big object, but we extract only what we need to display. For example, the ***name, description and image***.

{% hint style="info" %}
&#x20;The complete dApp treated in this example can be found [here](https://code.hyperdapp.dev/code/viewer/QmcCJt3wzTsHfnLPMXFBE4xo5YxDi1yS7yiTDptQMYY8oB) *-* *RINKEBY*
{% endhint %}
