đŸ’ŦFarcaster Casts

Learn how to fetch Farcaster Casts data using the Airstack API and its 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 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
      }
    }
  }
}

Get All Replies Of Certain Cast

You can fetch all the replies of a given cast by using the FarcasterCasts API and provide the cast's hash to the parentHash filter:

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        parentHash: {_eq: "0x1c11cc698e04105ccd4b219517a7808d21733838"}
      },
      blockchain: ALL
    }
  ) {
    Cast {
      castedAtTimestamp
      embeds
      fid
      castedBy {
        profileName
      }
      url
      text
      numberOfLikes
      numberOfRecasts
      numberOfReplies
      hash
    }
  }
}

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?