Migrating from v1 SDK
As of April 2024, the Forta Network has enabled the deployment of v2 detection bots. These are developed using the v2 bot SDK (which has version number beginning with 0.2.x
) as opposed to the v1 bot SDK (which has version number beginning with 0.1.x
). The primary benefit of v2 detection bots is that they enable developers to scan activity on any EVM-compatible chain (vs the 7 supported chains of v1 bots). Migrating your v1 bots to the v2 SDK is straightforward since the majority of code can be reused.
V1 Bots Will Be Deprecated
Support for v1 bots will be deprecated at some point in 2024, so migrating to v2 as soon as possible is encouraged.
The following steps will explain how to migrate your v1 bot:
Please see the Typescript starter project (or Javascript) for a working example of a v2 bot
- make sure you have NodeJS v20+ installed (using nvm is recommended i.e.
nvm install 20
) - import the new
@fortanetwork/forta-bot
package (instead offorta-agent
) - setup your bot's JSON-RPC provider using this guide
- exporting your handler functions is no longer required (but you still probably want to do this for unit testing)
- define your own async
main()
function in youragent.ts
file to serve as your bot's entrypoint, and then invoke it e.g. - if you have an
initialize
handler, then manually invoke it inmain()
and store any returned response in a variable e.g. - if you have a
handleBlock
handler, then add invocations forscanX()
inmain()
for each chain you want to scan and pass the handler as a parameter e.g. - if you have a
handleTransaction
handler, then add invocations forscanX()
inmain()
for each chain you want to scan and pass the handler as a parameter e.g. - if you have a
handleAlert
handler, then add an invocation forscanAlerts()
inmain()
and pass the handler as well as the required bot subscriptions as a parameter e.g. - add an invocation for
runHealthCheck()
inmain()
and if you defined a customhealthCheck
handler then pass the handler as a parameter e.g. - to attribute an alert to a specific chain/block/tx, use the
Finding.source
attribute e.g. - use the ethers.js
provider
(which is specific to the chain being scanned) passed as a second parameter intohandleBlock
andhandleTransaction
(instead of usinggetEthersProvider
) e.g. - update package.json to use the new
forta-bot
CLI tool (which needs to be added to thedevDependencies
as well) (see starter project package.json) - update the Dockerfile to use a base image of NodeJS 20+ (see starter project Dockerfile) e.g.
- ethers.js v6-specific migration:
BigNumber
is no longer used in ethers.js v6, and is replaced by the Typescript built-inBigInt
(so for example, you will need to make sure any event args you are parsing fromfilterLogs
orethers.provider
methods are handled asBigInt
)
Please see the Python starter project for a working example of a v2 bot
- make sure you have Python v3.10+ installed
- import the new
forta_bot_sdk
package (instead offorta_agent
) - setup your bot's JSON-RPC provider using this guide
- add an import for the
asyncio
package (used for running code asynchronously) - define your own async
main()
function in youragent.py
file to serve as your bot's entrypoint, and then invoke it usingasyncio.run
e.g. - add the
async
keyword in front of all your handler methods e.g. - if you have an
initialize
handler, then manually invoke it inmain()
and store any returned response in a variable e.g. - if you have a
handle_block
handler, then add invocations forscan_X()
inmain()
(as arguments toasyncio.gather
) for each chain you want to scan and pass the handler as a parameter e.g. - if you have a
handle_transaction
handler, then add invocations forscan_X()
inmain()
(as arguments toasyncio.gather
) for each chain you want to scan and pass the handler as a parameter e.g. - if you have a
handle_alert
handler, then add an invocation forscan_alerts()
inmain()
(as an argument toasyncio.gather
) and pass the handler as well as the required bot subscriptions as a parameter e.g. - add an invocation for
run_health_check()
inmain()
(as an argument toasyncio.gather
) and if you defined a customhealth_check
handler then pass the handler as a parameter e.g. - to attribute an alert to a specific chain/block/tx, use the
Finding.source
attribute e.g. - use the web3.py AsyncWeb3
provider
(which is specific to the chain being scanned) passed as a second parameter intohandle_block
andhandle_transaction
(instead of usingget_web3_provider
) e.g. - update package.json to use the new
forta-bot
CLI tool (which needs to be added to thedevDependencies
as well) (see starter project package.json) - update the Dockerfile to use a base image of Python 3.10+ (see starter project Dockerfile) e.g.