This tutorial uses the Neynar Rust SDK

This SDK is in beta and may change in the future. Please let us know if you encounter any issues or have suggestions for improvement.

Prerequisites

Project Setup

Initialize Project Directory

cargo new get-started-with-neynar-sdk
cd get-started-with-neynar-sdk

Add Neynar SDK as a dependency

cargo add --git https://github.com/neynarxyz/rust-sdk api

Implementation: Look up a user by their verified address

Replace the contents of src/main.rs with the following code:

  use neynar_sdk::apis::configuration as api_config;
  use neynar_sdk::apis::configuration::Configuration as ApiConfig;
  use neynar_sdk::apis::user_api::{
      FetchBulkUsersByEthOrSolAddressParams, fetch_bulk_users_by_eth_or_sol_address,
  };
  use neynar_sdk::models::BulkUserAddressType::VerifiedAddress;
  use reqwest::Client;

#[tokio::main]
async fn main() -> {
  let configuration = ApiConfig {
      base_path: "https://api.neynar.com/v2".to_string(),
      client: Client::builder().connection_verbose(true).build().unwrap(),
      user_agent: Some("rust-sdk-demo".to_string()),
      api_key: Some(api_config::ApiKey {
          prefix: None,
          key: "NEYNAR_API_DOCS".to_string(),
      }),
      basic_auth: None,
      bearer_access_token: None,
      oauth_access_token: None,
  };

  let addresses = "0xBFc7CAE0Fad9B346270Ae8fde24827D2D779eF07".to_string();
  let params = FetchBulkUsersByEthOrSolAddressParams {
      addresses,
      address_types: Some(vec![VerifiedAddress]),
      viewer_fid: None,
      x_neynar_experimental: None,
  };

  let result = fetch_bulk_users_by_eth_or_sol_address(&configuration, params).await;

  match result {
      Ok(response) => {
          println!("Users: {:?}", response.additional_properties);
      }
      Err(err) => {
          eprintln!("Failed to fetch users: {:?}", err);
          panic!("User fetch failed");
      }
  }
}

Running the project

cargo run

Result

You should see a response similar to this (formatted for readability):

Users [{
    fid: 20603,
    username: "topocount.eth",
    display_name: "Topocount",
    // ...other fields...
}]

Congratulations! You successfully set up the Neynar Rust SDK and used it to look up a user by their address!

Ready to start building?

Get your subscription at neynar.com and reach out to us on Telegram with any questions!