fatline-rs

Crates.iofatline-rs
lib.rsfatline-rs
version0.2.2
created_at2025-05-27 06:34:06.525174+00
updated_at2025-06-03 18:00:21.042616+00
descriptionFarcaster grpc client and utility library
homepage
repository
max_upload_size
id1690680
size3,181,476
(0x330a)

documentation

README

fatline-rs

Farcaster Rust client library

A 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
    • Users:

      • Get all user info (name,username,bio,url,pfp url) for specific fid
      • Get user signer validity info for specific fid
    • Hub info:

      • Get current registered fid count
      • Get storage information (global/user)
      • Probably more things as well
    • Streams:

      • Get all user casts by fid
      • Get all fids
      • Get all user link messages
      • Get all user profile updates
      • Get all user signer messages
      • Get all user reactions
      • Get all cast reactions
      • Get all casts by parent
    • Subscriptions:

      • (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

# 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:

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<dyn std::error::Error>> {
    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:

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:

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 for this)

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();
}
Commit count: 0

cargo fmt