Neynar Documentation

API Endpoints

Introduction

Farcaster Actions is a spec that allows Farcaster applications to securely communicate and perform actions on behalf of users across different apps. It enables an app (referred to as App A) to send data or trigger actions in another app ( App B) on behalf of a mutual user (e.g., Carol) by signing messages using the user’s Farcaster signer. This document provides an overview of how Farcaster Actions works and guides developers in implementing this functionality within their Neynar applications.

Overview of Farcaster Actions

Workflow

1. Requesting Signer Access

App A requests a Farcaster signer from the user ( Carol)

2. Making an API Call with Signer UUID and Metadata

App A prepares to send an action to App B by making an API call to the Neynar API, including:

3. Neynar API Produces a Signature

The Neynar API processes the request from App A:

4. Forwarding the Signed Message to App B

Neynar forwards the signed action to App B:

5. App B Verifies the Signature

Upon receiving the request, App B performs the following:

Implementation Details

For App A Developers

  1. Request Signer Access

  2. Prepare the Action Request

    • Define the action payload, including the type and any necessary data.
    • Specify the destination base URL of App B.
  3. Call the Neynar API

    • Make a POST request to the Neynar API endpoint (POST - /v2/farcaster/action) with the following structure:
   {
     "signer_uuid": "uuid-of-the-signer",
     "url": "https://appb.xyz",
     "action": {
       "type": "actionType",
       "payload": {
         // Action-specific data
       }
     }
   }
  1. Handle the Response
    • The Neynar API will forward the action to App B and return the response from App B.
    • Ensure proper error handling for cases where the action fails or the signature is invalid.

For App B Developers

  1. Set Up an Endpoint to Receive Actions

    • Create an HTTP endpoint to receive POST /api/farcaster/action requests from the Neynar API.
    • Ensure the endpoint URL is accessible and secured via HTTPS.
  2. Extract and Verify the Bearer Token

    • Extract the Authorization header from incoming requests.
    • Decode the bearer token to retrieve the header, payload, and signature.
    • Use the fid and public key from the token header to verify the signature against the payload.
  3. Process the Action

    • Once the signature is verified, extract the action payload from the request body.
    • Perform the necessary operations based on the action type and payload.
    • Update your application’s state or database as required.
  4. Respond to the Request

    • Return an appropriate HTTP response indicating success or failure.
    • Include any necessary data in the response body for App A to process.

Security Considerations

Conclusion

Farcaster Actions provides a secure and efficient way for Neynar apps to interact on behalf of users. By leveraging cryptographic signatures and Neynar’s API, apps can ensure that cross-app actions are authenticated and authorized by the user, enhancing trust and interoperability within the Neynar ecosystem.

Example

Action Schema

The action request sent to the Neynar API follows this schema:

{
  "signer_uuid": "string (UUID format)",
  "url": "string (valid URL)",
  "action": {
    "type": "string",
    "payload": {
      // Object containing action-specific data
    }
  }
}

Sample Request from App A to Neynar API POST/v2/farcaster/action Content-Type:application/json

{
  "signer_uuid": "123e4567-e89b-12d3-a456-426614174000",
  "url": "https://appb.example.com",
  "action": {
    "type": "sendMessage",
    "payload": {
      "message": "Hello from App A!"
    }
  }
}

Forwarded Request from Neynar API to App B POST/api/farcaster/action Content-Type:application/json Authorization: Bearer Token

{
  "action": {
    "type": "sendMessage",
    "payload": {
      "message": "Hello from App A!"
    }
  }
}

App B would then verify the bearer token and process the action accordingly.