@@ -11,7 +11,7 @@ assumes that you've already followed our
1111
1212:::
1313
14- Let's explore how use Ceramic to read messages from a stream. Ceramic nodes in the Recall network
14+ Let's explore how use Ceramic to read messages from a stream. Nodes in the Ceramic Network
1515subscribe to data by expressing an [ interest] ( /docs/protocol/ceramic-one/concepts#interests ) in a
1616given data model. This interest is broadcast to the node's peers in the network, who will then
1717initiate periodic synchronization of all data conforming to that model via [ Recon] ( # ) , a protocol
@@ -29,11 +29,15 @@ This method allows end users to register interest in a specific data model withi
2929network. The model's identifier is, itself, the ID of a stream that defines its schema.
3030
3131``` typescript
32- // My moddel stream ID
32+ import { CeramicClient , EventsFeedParams } from " @ceramic-sdk/http-client" ;
33+
34+ const ceramic = new CeramicClient ({ url: " http://localhost:5101" });
35+
36+ // My model stream ID
3337const modelId = " kjzl6hvfrbw6c5i55ks5m4hhyuh0jylw4g7x0asndu97i7luts4dfzvm35oev65" ;
3438
3539// Listen to all events written to instances of this modela
36- await ceramic .registerInterestModel (model );
40+ await ceramic .registerInterestModel (modelId );
3741```
3842
3943Upon success, the function won't return anything, but it will throw if there's an issue. You're now
@@ -53,9 +57,9 @@ but we'll define them to illustrate their purpose. If no limit is defined, the S
5357new events from the resume token.
5458
5559``` typescript
56- const params: EventFeedParams = {
60+ const params: EventsFeedParams = {
5761 limit: 50 ,
58- resumeAt: " myResumeToken " , // The resumeToken returned from the last call to `getEventsFeed`
62+ resumeAt: " 0 " , // The resumeToken returned from the last call to `getEventsFeed`
5963};
6064```
6165
@@ -92,10 +96,11 @@ type Event = {
9296};
9397```
9498
95- To fetch an event by it's id, we use ` getEvent `
99+ To fetch an event by its id, we use ` getEvent ` :
96100
97101``` typescript
98- const event = await ceramic .getEvent (myEventId );
102+ const eventId = events .events [0 ].id ; // The ID of the event we want to fetch
103+ const event = await ceramic .getEvent (eventId );
99104```
100105
101106There are also a small collection of simple helper functions to extract specific parts of an event.
@@ -105,32 +110,41 @@ There are also a small collection of simple helper functions to extract specific
105110Extract the data payload from an event.
106111
107112``` typescript
108- const data = await ceramic .getEventData (myEventId );
113+ const data = await ceramic .getEventData (eventId );
109114```
110115
111- This is equivalent to
116+ This is equivalent to:
112117
113118``` typescript
114- ceramic .getEvent (myEventId ).then ((event ) => event .data );
119+ ceramic .getEvent (eventId ).then ((event ) => event .data );
115120```
116121
117122#### ` getEventCAR `
118123
119124Extract the data payload from an event and parse it as a CAR file.
120125
121126``` typescript
122- const data = await ceramic .getEventCAR (myEventId );
127+ const data = await ceramic .getEventCAR (eventId );
123128```
124129
125130` data ` will be the parsed payload of the event.
126131
127132#### ` getEventType `
128133
129- This method is useful for cases where you know the schema of the payload. To use it, you must have a
130- [ codeco] ( https://github.com/ceramicnetwork/codeco ) codec handy.
134+ This method is useful for cases where you know the schema of the payload. To use it, you must have the
135+ [ codeco] ( https://github.com/ceramicnetwork/codeco ) package and your codec handy.
136+
137+ ``` bash
138+ npm install --save codeco
139+ ```
140+
141+ Then, you can use it like this:
131142
132143``` typescript
144+ import { Decoder } from " codeco" ;
145+
133146type MyPayload = /* ... */ ;
134147const decoder: Decoder <unknown , MyPayload > = /* ... */ ;
135- const data: MyPayload = await ceramic .getEventType (decoder , myEventId );
148+
149+ const data: MyPayload = await ceramic .getEventType (decoder , eventId );
136150```
0 commit comments