πŸ’¬Farcaster Casts

Learn how to fetch Farcaster Casts and related data using the Airstack API, and various use cases and combinations.

Table Of Contents

In this guide, you will learn to use Airstack to:

Pre-requisites

  • An Airstack account

  • Basic knowledge of GraphQL

Get Started

JavaScript/TypeScript/Python

If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:

React

npm install @airstack/airstack-react

Node

npm install @airstack/node

Then, add the following snippets to your code:

import { init, useQuery } from "@airstack/airstack-react";

init("YOUR_AIRSTACK_API_KEY");

const query = `YOUR_QUERY`; // Replace with GraphQL Query

const Component = () => {
  const { data, loading, error } = useQuery(query);

  if (data) {
    return <p>Data: {JSON.stringify(data)}</p>;
  }

  if (loading) {
    return <p>Loading...</p>;
  }

  if (error) {
    return <p>Error: {error.message}</p>;
  }
};

Other Programming Languages

To access the Airstack APIs in other languages, you can use https://api.airstack.xyz/gql as your GraphQL endpoint.

Get All Casts Casted In A Channel

You can fetch all the casts casted in a certain Farcaster channel by using the FarcasterCasts API and providing the Farcaster channel's URL to the channelUrl filter:

If you don't know the channel's URL, then find the channel's URL with this query here. The url field will return you the channel's URL associated with the given channel ID.

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        rootParentUrl: {
          # add channel URL here
          _eq: "https://warpcast.com/~/channel/airstack"
        }
      },
      blockchain: ALL
    }
  ) {
    Cast {
      castedAtTimestamp
      castedBy {
        profileName
        fid: userId
      }
      embeds
      fid
      hash
      text
      numberOfLikes
      numberOfRecasts
      numberOfReplies
    }
  }
}

Get All Casts Casted By A Farcaster User

You can fetch all the casts casted by a Farcaster user by using the FarcasterCasts API and providing the Farcaster user's fname or fid to the castedBy filter:

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        castedBy: {_eq: "fc_fname:betashop.eth"}
      },
      blockchain: ALL
    }
  ) {
    Cast {
      castedAtTimestamp
      embeds
      url
      text
      numberOfRecasts
      numberOfLikes
      channel {
        channelId
      }
      mentions {
        fid
        position
      }
    }
  }
}

Get All Casts That Have Frames

You can fetch all the casts casted that contain Frames by using the FarcasterCasts API and set the hasFrames filter to true:

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        # Make sure to have `hasFrames` to true
        hasFrames: {_eq: true}
      },
      blockchain: ALL
    }
  ) {
    Cast {
      castedAtTimestamp
      embeds
      url
      text
      numberOfRecasts
      numberOfLikes
      channel {
        channelId
      }
      mentions {
        fid
        position
      }
      frame {
        buttons {
          action
          id
          index
          target
        }
        frameUrl
        imageAspectRatio
        imageUrl
        inputText
        postUrl
        state
      }
    }
  }
}

Get All Casts That Have Embeds

You can fetch all the casts casted that contain Frames by using the FarcasterCasts API and set the hasEmbeds filter to true:

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        # Make sure to set `hasEmbeds` to true
        hasEmbeds: {_eq: true}
      },
      blockchain: ALL
    }
  ) {
    Cast {
      castedAtTimestamp
      embeds
      url
      text
      numberOfRecasts
      numberOfLikes
      channel {
        channelId
      }
      mentions {
        fid
        position
      }
    }
  }
}

Get All Casts Casted At Certain Period Of Time

You can fetch all the casts casted that contain Frames by using the FarcasterCasts API and providing the time period to the castedAtTimestamp filter with the appropriate operators:

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        # Make sure to set `castedTimestamp` with the matching operator
        # to filter by the desired time period
        castedAtTimestamp: {_gte: "2024-01-01T00:00:00Z"}
      },
      blockchain: ALL
    }
  ) {
    Cast {
      castedAtTimestamp
      embeds
      url
      text
      numberOfRecasts
      numberOfLikes
      channel {
        channelId
      }
      mentions {
        fid
        position
      }
    }
  }
}

Get All Casts That Have Mentions

You can fetch all the casts casted that contain mentions by using the FarcasterCasts API and set the hasMentions filter to true:

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        # Make sure to set `hasMentions` to true
        hasMentions: {_eq: true}
      },
      blockchain: ALL
    }
  ) {
    Cast {
      castedAtTimestamp
      embeds
      url
      text
      numberOfRecasts
      numberOfLikes
      channel {
        channelId
      }
      mentions {
        fid
        position
      }
    }
  }
}

Get Details Of A Certain Cast

You can fetch all the details, including text, embeds, url, social capital value, etc., of a given cast by using the FarcasterCasts API and provide the cast's URL from Warpcast the url filter:

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        url: {_eq: "https://warpcast.com/dannylove/0xabc68559"}
      },
      blockchain: ALL
    }
  ) {
    Cast {
      castedAtTimestamp
      embeds
      text
      numberOfRecasts
      numberOfLikes
      numberOfReplies
      channel {
        channelId
      }
      mentions {
        fid
        position
      }
      socialCapitalValue {
        rawValue
        formattedValue
      }
    }
  }
}

Developer Support

If you have any questions or need help regarding fetching Farcaster Casts data, please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?