Skip to content

[SDK] Transactions

FTCHD edited this page Sep 8, 2024 · 2 revisions

Sometimes you want your handler to return transaction data instead of a Frame.

To achieve this on FrameTrain, you return a transaction object in your handler.

FrameTrain's transaction field is fully compatible with the Farcaster transaction spec.

Example

import type { BuildFrameData, FramePayloadValidated } from '@/lib/farcaster'

export default async function yourHandler({
    config,
    params,
}: {
    body: FramePayloadValidated
    config: Config
    storage: Storage
    params: any
}): Promise<BuildFrameData> {
    // do any logic you need to build the transaction data

    // return the data in a transaction object
    return {
        transaction: {
            chainId: myChainId,
            method: 'eth_sendTransaction',
            params: {
                to: session.unsignedTransaction.to,
                value: session.unsignedTransaction.value,
                data: session.unsignedTransaction.input,
                abi: [],
            },
        },
    }
}