Skip to content
Interact with data stored on IPFS nodes.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Interact with files on IPFS

There are very few file storage options available for Elm which can easily be incorporated into packages. This package attempts to fix part of this problem by building file storage on top of the IPFS HTTP API.

Using the IPFS API

All of the API calls to IPFS are implemented via Http.task. By doing this, you are able to supply callbacks into the IPFS code easily.

Task example

Here is a minimal complete example showing how to view the 'readme' file on an IPFS node. It mirrors the example in the Getting Started section of the IPFS documentation.

import Browser
import Html
import Ipfs
import Task

type Msg
    = ShowReadme (Result Ipfs.Error String)

showReadme : Cmd Msg
showReadme =
    Task.attempt ShowReadme <|
            Maybe.map2 Tuple.pair
                (Ipfs.node "")
                (Ipfs.hash <|
                        ++ "/readme"
            Just ( node, hash ) ->
       node hash

            Nothing ->
       <| Ipfs.IpfsError "invalid node or hash"

main : Program () String Msg
main =
        { init = always ( "testing", showReadme )
        , view = Html.text >> List.singleton >> Html.pre []
        , subscriptions = always Sub.none
        , update =
            \(ShowReadme result) _ ->
                case result of
                    Ok x ->
                        ( x, Cmd.none )

                    Err x ->
                        ( Ipfs.errorToString x, Cmd.none )

You can read more about tasks in the Task module.


I have plans to add more to this - likely mutable files, and encrypted files. Stay tuned!

You can’t perform that action at this time.