This guide will explore the basics of creating a Forta detection bot.
Before you start, please make sure you have the following:
- High-level understanding of Forta detection bot development
- Node.js v12+ (which includes the Node package manager i.e. npm)
- Python v3.6+ (only if you want to use Python SDK)
- Docker v20+ (including the buildx plugin)
- Basic understanding of Ethereum and smart contracts
- MATIC tokens for deploying your bot (see this guide)
Initializing a project
The above snippet creates a new project directory called
my-new-bot, and then uses
npx (a package runner tool that is part of npm 5.2+) to invoke the
init command of the
forta-agent CLI tool. By passing the
--python is also an option).
Using @latest version
We recommend always initializing projects with
@latest version to ensure you have the latest and greatest SDK features. Otherwise, you may end up using an older previously cached version.
init command will initialize a forta.config.json and a keyfile for you in the ~/.forta folder (you will be prompted for a password for the keyfile). The forta.config.json file will be used throughout the development lifecycle of your bots. Several files will also be created inside of your project folder, including a package.json file, tsconfig.json (for Typescript) and a src folder. Dependencies of the project will also be installed for you by running
Protecting your keyfile
Make sure you do not forget the password for your keyfile as we have no way to recover it! We also recommend keeping a backup of it. The keyfile is located in the ~/.forta folder and named in the format
UTC--<created_at UTC ISO8601>--<address hex> (an example name would be
UTC--2021-07-12T01:37:55.270Z--577022b59d1c25623ac523fe78d2f6347b5c69f2). This keyfile will primarily be used for publishing your bot. You can get the absolute path to your keyfile using the
npm run keyfile command from the project folder.
Awesome! You have successfully completed setting up your project. See below for ideas/examples of bots, or continue to testing your bot.
Ideas for bots
We’re excited to see what sort of innovative bots the community comes up with! A good place to start is to choose a specific protocol that you use or would love to build bots for. You could also choose based on TVL ranking as listed on DeFi Pulse. If you’re looking for some inspiration to get started, here are possible ideas for bots:
- Detect admin functions
- Detect high gas transactions
- Detect ownership transfers of contracts
- Detect high volume of failed transactions from an account
- Detect flash loan attacks
- Detect sandwich attacks
- Detect when an oracle is returning bad values
- Detect transactions from a known list of blacklisted addresses