Feeds ======================== .. note:: Feeds, previously known as *Mutable Resource Updates*, is an experimental feature, available since Swarm POC3. It is under active development, so expect things to change. Since Swarm hashes are content addressed, changes to data will constantly result in changing hashes. Swarm Feeds provide a way to easily overcome this problem and provide a single, persistent, identifier to follow sequential data. The usual way of keeping the same pointer to changing data is using the Ethereum Name Service (ENS). However, since ENS is an on-chain feature, it might not be suitable for each use case since: 1. Every update to an ENS resolver will cost gas to execute 2. It is not be possible to change the data faster than the rate that new blocks are mined 3. ENS resolution requires your node to be synced to the blockchain Swarm Feeds provide a way to have a persistent identifier for changing data without having to use ENS. It is named Feeds for its similarity with a news feed. If you are using *Feeds* in conjunction with an ENS resolver contract, only one initial transaction to register the "Feed manifest address" will be necessary. This key will resolve to the latest version of the Feed (updating the Feed will not change the key). You can think of a Feed as a user's Twitter account, where he/she posts updates about a particular Topic. In fact, the Feed object is simply defined as: .. code-block:: go type Feed struct { Topic Topic User common.Address } That is, a specific user posting updates about a specific Topic. Users can post to any topic. If you know the user's address and agree on a particular Topic, you can then effectively "follow" that user's Feed. .. important:: How you build the Topic is entirely up to your application. You could calculate a hash of something and use that, the recommendation is that it should be easy to derive out of information that is accesible to other users. For convenience, ``feed.NewTopic()`` provides a way to "merge" a byte array with a string in order to build a Feed Topic out of both. This is used at the API level to create the illusion of subtopics. This way of building topics allows using a random byte array (for example the hash of a photo) and merge it with a human-readable string such as "comments" in order to create a Topic that could represent the comments about that particular photo. This way, when you see a picture in a website you could immediately build a Topic out of it and see if some user posted comments about that photo. Feeds are not created, only updated. If a particular Feed (user, topic combination) has never posted to, trying to fetch updates will yield nothing. Feed Manifests -------------- A Feed Manifest is simply a JSON object that contains the ``Topic`` and ``User`` of a particular Feed (i.e., a serialized ``Feed`` object). Uploading this JSON object to Swarm in the regular way will return the immutable hash of this object. We can then store this immutable hash in an ENS Resolver so that we can have a ENS domain that "follows" the Feed described in the manifest. Feeds API --------- There are 3 different ways of interacting with *Feeds* : HTTP API, CLI and Golang API. HTTP API ~~~~~~~~ Posting to a Feed ................. Since Feed updates need to be signed, and an update has some correlation with a previous update, it is necessary to retrieve first the Feed's current status. Thus, the first step to post an update will be to retrieve this current status in a ready-to-sign template: 1. Get Feed template ``GET /bzz-feed:/?topic=&user=&meta=1`` ``GET /bzz-feed://?meta=1`` Where: + ``user``: Ethereum address of the user who publishes the Feed + ``topic``: Feed topic, encoded as a hex string. Topic is an arbitrary 32-byte string (64 hex chars) .. note:: + If ``topic`` is omitted, it is assumed to be zero, 0x000... + if ``name=`` (optional) is provided, a subtopic is composed with that name + A common use is to omit topic and just use ``name``, allowing for human-readable topics You will receive a JSON like the below: .. code-block:: js { "feed": { "topic": "0x6a61766900000000000000000000000000000000000000000000000000000000", "user": "0xdfa2db618eacbfe84e94a71dda2492240993c45b" }, "epoch": { "level": 16, "time": 1534237239 } "protocolVersion" : 0, } 2. Post the update Extract the fields out of the JSON and build a query string as below: ``POST /bzz-feed:/?topic=&user=&level=&time=