farcaster_rs/lib.rs
1//! # farcaster-rs
2//! A Rust crate to interact with the [Farcaster](https://farcaster.xyz) smart contracrts & merkle APIs
3//!
4//! # Quickstart
5//! To get started with the farcaster-rs crate, this should serve as a simple example of how to use it
6//!
7//! ```no_run
8//! use farcaster_rs::{
9//! Account,
10//! Farcaster
11//! };
12//! use std::error::Error;
13//!
14//! #[tokio::main]
15//! async fn main() -> Result<(), Box<dyn Error>> {
16//! // Initialize a new Account w/ your key and an optional token duration (milliseconds)
17//! let account: Account = Account::from_mnemonic("super top secret phrase", None).await?;
18//!
19//! // Connect to an ETH node
20//! let farcaster: Farcaster = Farcaster::new("node url", account).await?;
21//!
22//! // Get Dan Romero's Casts with his Username, while specifying a limit, and a cursor
23//! let casts = farcaster.get_casts_by_username("dwr", Some(5), None).await?;
24//!
25//! println!("{:#?}", casts);
26//!
27//! Ok(())
28//! }
29//! ```
30//! Quick explanation of all folders/modules in farcaster-rs
31//!
32//!
33//! ## If you're looking for authentication
34//! It's best to look in the [Account Struct](./types/account/struct.Account.html)
35//!
36//! ## If you're looking for most protocol-related functions
37//! It's best to look in the [Farcaster Struct](./struct.Farcaster.html)
38//!
39//! ## If you're looking to convert stuff like Username -> FID, FID -> Address, etc....
40//! It's best to look in the [Registry Struct](./types/registry/struct.Registry.html)
41//!
42//! ---------------
43//! ## `account`
44//! The account module handles authentication w/ the Farcaster Merkle APIs. Generating tokens, revoking tokens, etc....
45//! View documentation [here](./account/index.html)
46//!
47//! ## `api`
48//! The API module has room for growth, but for now holds some reqwest wrappers to make my life easier
49//! View documentation [here](./api/index.html)
50//!
51//! ## `assets`
52//! The assets module holds functions to get NFT collection related data.
53//! View documentation [here](./assets/index.html)
54//!
55//! ## `casts`
56//! The casts module holds functions related to casts on Farcaster. Getting casts, publishing casts, etc...
57//! View documentation [here](./casts/index.html)
58//!
59//! ## `follows`
60//! The follows module holds function related to followers and following. Follow users, unfollow, view followers, etc..
61//! View documentation [here](./follows/index.html)
62//!
63//! ## `misc`
64//! The misc module holds functions that don't entirely have a place. The only one for now is API Health
65//! View documentation [here](./misc/index.html)
66//!
67//! ## `notifications`
68//! The notifications module holds functions relating to notifications, which right now allows you to fetch notifications
69//! //! View documentation [here](./notifications/index.html)
70//!
71//! ## `reactions`
72//! The reactions module allows you to view and modify your reactions. Like, recast, list likes/recasts, etc...
73//! View documentation [here](./reactions/index.html)
74//!
75//! ## `registry`
76//! The registry module holds important functions most importantly relating to getting users.
77//! - Convert addres/username to FID, get users via FID, etc......
78//! View documentation [here](./registry/index.html)
79//! ## `users`
80//! The users module holds functions relating to users on Farcaster. Get users, get custody adress', etc...
81//! //! View documentation [here](./users/index.html)
82//!
83//! ## `verifications`
84//! The verifications module holds functions relating to cryptographic proofs such as getting verified address'
85//! //! View documentation [here](./verifications/index.html)
86
87pub mod account;
88pub mod api;
89pub mod assets;
90pub mod casts;
91pub mod constants;
92pub mod follows;
93pub mod misc;
94pub mod notifications;
95pub mod reactions;
96pub mod registry;
97pub mod types;
98pub mod users;
99pub mod verifications;
100
101pub use types::account::Account;
102pub use types::registry::Registry;
103
104use std::error::Error;
105
106/// The Farcaster type that holds the keys to the castle - so to speak :)
107#[derive(Debug)]
108pub struct Farcaster {
109 #[allow(dead_code)]
110 pub account: Account,
111 pub registry: Registry,
112}
113
114impl Farcaster {
115 pub async fn new(ethereum_provider: &str, account: Account) -> Result<Self, Box<dyn Error>> {
116 let registry = Registry::new(ethereum_provider).await?;
117
118 Ok(Farcaster { account, registry })
119 }
120}