> ## Documentation Index
> Fetch the complete documentation index at: https://docs.neynar.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Farcaster Bots via Script Using Neynar SDK

> Complete guide to creating Farcaster bots on Neynar with automated scripts. Learn to set up bot accounts, manage dedicated signers, and deploy automated social interactions using Neynar SDK with ready-to-use examples and templates.

<Info>
  ### 1. If you need to create a new bot / agent account, see [Create Farcaster bot (UI)](/docs/create-farcaster-bot-ui) instead

  2. Simplest way to start is to clone this git repo that has a sample bot ready to go: [https://github.com/neynarxyz/farcaster-examples](https://github.com/neynarxyz/farcaster-examples)
</Info>

In our `farcaster-examples` repo, `gm_bot` is an automated messaging bot designed to cast a 'gm <Icon icon="planet-ringed" iconType="solid" />' message in Warpcast every day at a scheduled time. The bot operates continuously as long as the system remains online. It leverages [Neynar API](https://docs.neynar.com/) and is built using [@neynar/nodejs-sdk](https://www.npmjs.com/package/@neynar/nodejs-sdk).

## Prerequisites

* [Node.js](https://nodejs.org/en/): A JavaScript runtime built on Chrome's V8 JavaScript engine. Ensure you have Node.js installed on your system.

## Installation

### Setting Up the Environment

<Steps>
  <Step title="Install PM2">
    PM2 is a process manager for Node.js applications. Install it globally using npm:

    <CodeGroup>
      ```bash Bash theme={"system"}
      npm install -g pm2
      ```
    </CodeGroup>
  </Step>

  <Step title="Install Project Dependencies">
    Navigate to the project directory and run one of the following commands to install all required dependencies:

    <CodeGroup>
      ```Text Yarn theme={"system"}
      yarn install
      ```

      ```bash npm theme={"system"}
      npm install
      ```
    </CodeGroup>
  </Step>

  <Step title="Configure Environment Variables">
    * Copy the example environment file:
          <CodeGroup>
            ```bash bash theme={"system"}
            cp .env.example .env
            ```
          </CodeGroup>
    * Open the repo in your favorite editor and edit `.env` file to add your `NEYNAR_API_KEY` and `FARCASTER_BOT_MNEMONIC`. Optionally, you can also specify `PUBLISH_CAST_TIME` and `TIME_ZONE` for custom scheduling.
  </Step>
</Steps>

### Generating a Signer for an existing account

Before running the bot, you need to generate a signer and get it approved via an onchain transaction. You can easily generate a signer by using the Neynar Dev portal at [https://dev.neynar.com](https://dev.neynar.com).

<Steps>
  <Step>
    Login to your Neynar dev portal
  </Step>

  <Step>
    App -> "Agents and bots" -> "use existing account"
  </Step>

  <Step>
    <Frame>
      <img src="https://mintcdn.com/neynar/4PNY113y9N9T-r9z/images/docs/c4e898688e9c165b0be84280f7f4aa3ba65d7041448a3e8d22e2dbd7ac58309a-image.png?fit=max&auto=format&n=4PNY113y9N9T-r9z&q=85&s=961e0c13bb6852ec428aa7d657387ddb" alt="Login to your Neynar dev portal" width="2012" height="230" data-path="images/docs/c4e898688e9c165b0be84280f7f4aa3ba65d7041448a3e8d22e2dbd7ac58309a-image.png" />
    </Frame>

    Click the Sign in With Neynar button
  </Step>

  <Step>
    Connect the bot's address, the Warpcast logged-in user must be the bot
  </Step>

  <Step>
    If everything goes well, there will be a signer UUID, which can be used to cast as the bot!
  </Step>
</Steps>

## Running the Bot

<Steps>
  <Step title="Start the Bot">
    Launch the bot using the following command:

    <CodeGroup>
      ```bash Yarn theme={"system"}
      yarn start
      ```

      ```Text npm theme={"system"}
      npm run start
      ```
    </CodeGroup>
  </Step>

  <Step title="Verify the Process">
    Ensure that the bot is running correctly with:

    <CodeGroup>
      ```bash bash theme={"system"}
      pm2 status
      ```
    </CodeGroup>
  </Step>

  <Step title="View Logs">
    To check the bot's activity logs, use:

    <CodeGroup>
      ```bash bash theme={"system"}
      pm2 logs
      ```
    </CodeGroup>
  </Step>

  <Step title="Stopping the Bot">
    If you need to stop the bot, use:

    <CodeGroup>
      ```bash bash theme={"system"}
      pm2 kill
      ```
    </CodeGroup>
  </Step>
</Steps>

## License

`gm_bot` is released under the MIT License. This license permits free use, modification, and distribution of the software, with the requirement that the original copyright and license notice are included in any substantial portion of the work.

## FAQs/Troubleshooting

<Accordion title="What if gm_bot stops sending messages?">
  Check the PM2 logs for any errors and ensure your system's time settings align with the specified `TIME_ZONE`, also ensure that the process is running.
</Accordion>

<Info>
  ### Ready to start building?

  Get your subscription at [neynar.com](https://neynar.com) and reach out to us on [Slack](https://neynar.com/slack) with any questions!
</Info>
