https://github.com/0x330a-public/fatline-rs
https://github.com/0x330a-public/fatline-rs
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/0x330a-public/fatline-rs
- Owner: 0x330a-public
- License: mit
- Created: 2024-02-20T04:20:49.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-15T06:43:06.000Z (2 months ago)
- Last Synced: 2025-03-31T02:13:58.500Z (about 2 months ago)
- Language: Rust
- Size: 66.4 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-farcaster - 0x330a-public/fatline-rs
README
# fatline-rs
## Farcaster Rust client libraryA library project to re-export some common Farcaster client RPC code and utilities,
so that someone could interface with their own Farcaster Hub.## Planned Features
- [ ] Wrap basic Hub client and expose specific functions at a higher level
- [x] Users:
- [x] Get all user info (name,username,bio,url,pfp url) for specific fid
- [x] Get user signer validity info for specific fid
- [ ] Hub info:
- [x] Get current registered fid count
- [ ] Get storage information (global/user)
- [ ] Probably more things as well
- [ ] Streams:
- [x] Get all user casts by fid
- [x] Get all fids
- [x] Get all user link messages
- [x] Get all user profile updates
- [x] Get all user signer messages
- [x] Get all user reactions
- [x] Get all cast reactions
- [x] Get all casts by parent
- [ ] Subscriptions:
- [x] (WIP) Subscriptions for all new merged events from hub (for processing incoming updates of all types)
- [ ] Refactor everything to use the library specific types instead of relying on consumers to use the prost / protobuf types
- [ ] Implement macros for a lot of the repeated functions to make improvements easier## Usage
### Dependencies
Add the dependency to your project
```toml
# Cargo.toml[dependencies.fatline-rs]
git = "https://github.com/0x330a-public/fatline-rs.git"
features = ["client"]
rev = "00aabbccdd..." # latest github commit while in early dev
```
(Maybe the protobuf dependencies are required for the build script I'm not sure):nixpkgs: `protobuf`
### Usage in project
Setting up the environment for authenticated calls:
```rust
use fatline_rs::{HubServiceClient, MessageTrait, SigningKey, VerifyingKey};
use fatline_rs::proto::{CastAddBody, FarcasterNetwork, HashScheme, Message, MessageData, MessageType, SignatureScheme};
use fatline_rs::proto::message_data::Body::CastAddBody as CABody;
use fatline_rs::utils;#[tokio::main]
async fn main() -> Result<(), Box> {
let mut private_bytes: [u8; 32] = [0u8; 32];
hex::decode_to_slice("aabbccddeeff...", &mut private_bytes).unwrap();
let my_fid = 123456;
let key = SigningKey::from(private_bytes);let mut client = HubServiceClient::connect("grpc://[some url or IP address]:2283").await?;
// ... use client / key in examples below ...
}
```Updating your profile:
```rust
fn main () {
// ... setup ...
// Profile update using builder
let update = ProfileUpdateBuilder::create_empty()
.username_update(FieldUpdate::Add("username".to_string()))
.display_name_update(FieldUpdate::Add("Username".to_string()))
.bio_update(FieldUpdate::Remove)
// .github_update()
// .twitter_update()
// .location_update()
// .url_update()
// .profile_pic_update()
.build()?;
}
```Making a post:
```rust
fn main() {
// ... setup ...
// Construct the cast creation using a builder
let update = CastCreateBuilder::create_empty()
.body("@Farcaster cool cast".to_string())
// .parent(Parent::CastId(etc)
// .embeds(vec![Embed::Url("https://something.com".to_string())])
// .mentions(vec![Mention { fid: 1, start_pos: 0 }])
.build()?;let result = client.submit_bulk_messages(update.to_messages(my_fid, &key)).await?;
println!("{:?}", result);
}```
### Creating a Farcaster account programmatically
Firstly, create an ed25519 Signing key if you don't have the bytes already to create one:
(You can also use [jesse](https://github.com/0x330a-public/jesse) for this)
```rust
use fatline_rs::utils::generate_signing_key;fn main() {
// *****INITIAL SETUP*****
// 1. generate a signing key
let key = generate_signing_key();
// 2. print out the hex encoded bytes here to re-use the same key
println!("keep this one secret: {}", hex::encode(key.as_bytes()));
// 3. add the signing key to your farcaster account
// open this in browser, just easier to highlight this way
let verifying_key = VerifyingKey::from(&key);
println!("publish this one in dashboard: {}", hex::encode(verifying_key.as_bytes()));
let dashboard_url = "https://terminex.mempool.online";
// connect registered farcaster wallet -> add key -> paste hex output of verifying key ^ -> submit tx
// ************************
// 4. disregard the above lines and re-build your key from saved output from first run
let mut private_bytes: [u8; 32] = [0u8; 32];
hex::decode_to_slice("aabbccddeeff...", &mut private_bytes).unwrap();
}
```