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({
  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.

Authenticate & Upload a new deployment

Authenticate with the command below.

terminal
npx convect-xyz auth

Create a new deployment with the command below.

terminal
npx convect-xyz deploy -s <project name>/<function name>