Quickstart

Write your handler

This example uses Wagmi CLI to generate the ABI and token address. Using Wagmi and ABIs is entirely optional. Alternatively, you can specify the event signature in string format by replacing eventName and abi with the signature property.

src/convect/transfer.ts
import { tokenABI, tokenAddress } from './abis/token'
import { log, transaction } from "convect-xyz";

export const transfer = transaction({
  logs: [
    log({
      origin: tokenAddress,
      abi: tokenABI,
      eventName: "Transfer"
    })
  ],
  handler: async (transactions) => {
    // Implement your transaction handler here. eg.
    await prisma.activity.createMany({
      data: transactions.flatMap(tx => tx.logs).map((log) => ({
        from: log.args.from // Inferred as `0x${string}`,
        to: log.args.to // Inferred as `0x${string}`,
        tokenId: log.args.tokenId // Inferred as bigint
      }))
    })
  }
});
Convention
For better readability, define related handlers in a separate file as shown above.

Export a convect function

src/convect/example.convect.ts
import { transfer } from "./transfer";
import { convect } from "convect-xyz";

export default convect({
  id: "<id you copied in step 1>",
  handlers: [transfer]
});
Good to know
When your Convect Function receives batches of transactions, it will call all matching transaction handlers in the order they are specified in the handlers array.

Upload a new deployment

Obtain an API Key from the Convect App and run the following command from your project root directory. The Convect CLI will look for all files in subdirectories ending with a .convect.ts extension. Select the file you just created.

terminal
export CONVECT_API_KEY="<Your API Key>"
npx convect-xyz init