Client
A Client established a connection with a Farcaster Hub and can be used to send and receive messages. It is initialized
with the IP address and gRPC port of the Hub. Once connected, a Client instance can:
- Query for messages by user or type.
- Query for on-chain Farcaster Contracts state.
- Subscribe to changes by type.
- Upload new messages.
Constructor
getInsecureHubRpcClient returns a Hub RPC Client. Use getSSLHubRpcClient if the server you're using supports SSL.
Usage
Returns
| Type |
Description |
Client |
A new Client instance. |
Parameters
| Name |
Type |
Description |
address |
string |
Address and RPC port string (e.g. https://testnet1.farcaster.xyz:2283) |
Authentication
Some Hubs require authentication to submit messages which is done with basic auth over SSL. Clients will automatically
negotiate an SSL connection if possible, and you'll need to provide the username and password when calling submitMessage.
Methods
Clients expose methods grouped into logical services. Each method returns an async Result
object and may support pagination.
- Signers
- UserData
- Casts
- Reactions
- Verifications
- Events
- Submit
- Contracts
Results
Methods are async and return a HubAsyncResult<T>, a wrapper around neverthrow's Result, which contains either a
successful response of type <T> or an error value. There are three types of return values across all our methods:
Results always return an object of type Message instead of a more specific type like CastAddMessage due to a quick of the protobuf-generated types. This can be easily remedied by passing responses through a typeguard:
Methods that return multiple values support pagination in requests with a pageSize and pageToken property.
Method Request Documentation
getSigner
Returns an active signer message given an fid and the public key of the signer.
Usage
Returns
| Type |
Description |
MessageResult<SignerAddMessage> |
A SignerAdd message. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
signer |
string |
The public key of the signer. |
getSignersByFid
Returns all active signers created by an fid in reverse chronological order.
Usage
Returns
| Type |
Description |
MessagesResult<SignerAddMessage> |
One or more SignerAdd messages. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
getAllSignerMessagesByFid
Returns all active and inactive signers created by an fid in reverse chronological order.
Usage
Returns
| Type |
Description |
MessagesResult<(SignerAddMessage | SignerRemoveMessage)> |
Zero or more SignerAdd or SignerRemove messages |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
getUserData
Returns a specific piece of metadata about the user.
Usage
Returns
| Type |
Description |
MessageResult<UserDataAddMessage> |
The UserDataAdd message. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
type |
UserDataType |
The type of user metadata. |
getUserDataByFid
Returns all metadata about the user.
Usage
Returns
| Type |
Description |
MessagesResult<UserDataAddMessage> |
Zero or more UserDataAdd messages. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
reverse? |
boolean |
Reverses the chronological ordering. |
getAllUserDataMessagesByFid
An alias for getUserDataByFid
getCast
Returns an active cast for a user.
Usage
Returns
| Type |
Description |
MessageResult<CastAddMessage> |
The CastAdd message |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
hash |
string |
The hash of the cast. |
getCastsByFid
Returns active casts for a user in reverse chronological order.
Usage
Returns
| Value |
Description |
MessagesResult<CastAddMessage> |
Zero or more CastAdd messages. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
getCastsByMention
Returns all active casts that mention an fid in reverse chronological order.
Usage
Returns
| Value |
Description |
MessagesResult<CastAddMessage> |
Zero or more CastAdd messages. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid that is mentioned in the casts. |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
getCastsByParent
Returns all active casts that are replies to a specific cast in reverse chronological order.
Usage
Returns
| Value |
Description |
MessagesResult<CastAddMessage> |
Zero or more CastAdd messages. |
Parameters
| Name |
Type |
Description |
parent |
CastId |
The CastId of the parent cast. |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
getAllCastMessagesByFid
Returns all active and inactive casts for a user in reverse chronological order.
Usage
Returns
| Value |
Description |
MessagesResult<(CastAddMessage|CastRemoveMessage)> |
Zero or more CastAdd or CastRemove messages. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
getReaction
Returns an active reaction of a particular type made by a user to a cast.
Usage
Returns
| Type |
Description |
MessageResult<ReactionAddMessage> |
A ReactionAdd message. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
type |
ReactionType |
The type of the reaction. |
cast |
CastId |
The cast id. |
getReactionsByCast
Returns all active reactions made by users to a cast.
Usage
Returns
| Value |
Description |
MessagesResult<ReactionAddMessage> |
Zero or more ReactionAdd messages. |
Parameters
| Name |
Type |
Description |
cast |
CastId |
The cast id. |
type? |
ReactionType |
(optional) The type of the reaction. |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
getReactionsByFid
Returns all active reactions made by a user in reverse chronological order.
Usage
Returns
| Type |
Description |
MessagesResult<ReactionAddMessage> |
Zero or more ReactionAdd messages. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user |
reactionType? |
ReactionType |
The type of the reaction |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
getAllReactionMessagesByFid
Returns all active and inactive reactions made by a user in reverse chronological order.
Usage
Returns
| Type |
Description |
MessagesResult<ReactionAddMessage|ReactionRemoveMessage> |
Zero or more ReactionAdd or ReactionRemove messages. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
getVerification
Returns an active verification for a specific Ethereum address made by a user.
Usage
Returns
| Type |
Description |
MessageResult<VerificationAddEthAddressMessage> |
A VerificationAddEthAddress message. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
address |
string |
The Ethereum address being verified. |
getVerificationsByFid
Returns all active verifications for Ethereum addresses made by a user in reverse chronological order.
Usage
Returns
| Value |
Description |
MessagesResult<VerificationAddEthAddressMessage> |
Zero or more VerificationAddEthAddress messages. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
getAllVerificationMessagesByFid
Returns all active and inactive verifications for Ethereum addresses made by a user in reverse chronological order.
Usage
Returns
| Type |
Description |
MessagesResult<VerificationAddEthAddressMessage|VerificationRemoveMessage> |
Zero or more VerificationAddEthAddress or VerificationRemove messages. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
pageSize? |
number |
Number of results per page. |
pageToken? |
Uint8Array |
Token used to fetch the next page, if it exists. |
reverse? |
boolean |
Reverses the chronological ordering. |
subscribe
Returns a gRPC Stream object which emits HubEvents in real-time.
Streams emit events from the current timestamp onwards and gRPC guarantees ordered delivery. If a Client is
disconnected, it can request the stream to begin from a specific Event Id. Hubs maintain a short cache of events
which helps with recovery when clients get disconnected temporarily.
Usage
Returns
| Value |
Description |
HubResult<ClientReadableStream<HubEvent>> |
A stream that emits HubEvents. |
Parameters
| Name |
Type |
Description |
eventTypes |
HubEventType |
Events to listen for. |
fromId? |
number |
EventId to start streaming from. |
submitMessage
Submits a new message to the Hub. A Hub can choose to require basic authentication or enforce IP-based rate limits for messages accepted over this endpoint from clients.
Usage
Returns
| Value |
Description |
MessageResult<T> |
The message that was submitted. |
Parameters
| Name |
Type |
Description |
message |
Message |
The message being submitted |
metadata? |
string |
(optional) Username and password metadata for authentication |
getIdRegistryEvent
Returns the on-chain event most recently associated with changing an fid's ownership.
Usage
Returns
| Value |
Description |
HubAsyncResult<IdRegistryEvent> |
An IdRegistryEvent. |
Parameters
| Name |
Type |
Description |
fid |
number |
The fid of the user. |
getNameRegistryEvent
Returns the on-chain event most recently associated with changing an fname's ownership.
Usage
Returns
| Value |
Description |
HubAsyncResult<NameRegistryEvent> |
A NameRegistryEvent. |
Parameters
| Name |
Type |
Description |
fname |
string |
The fname of the user. |
Method Response Documentation
MessageResult
A documentation alias for HubAsyncResult<Message> where the success value contains a single message.
Message are of the type requested but this is an implicit guarantee since ts-proto does not generate bindings
correctly to reflect this in the returned types.
MessagesResult
A documentation alias for HubAsyncResult<MessagesResponse> where the success value contains a MessagesResponse object.
Messages are of the type requested but this is an implicit guarantee since ts-proto does not generate bindings
correctly to reflect this in the returned types.
| Name |
Type |
Description |
messages |
Message[] |
Messages that were a response to the query. |
nextPageToken? |
Uint8Array | undefined |
Token used to fetch the next page, if it exists. |