Skip to content

Conversation

bh2smith
Copy link
Member

@bh2smith bh2smith commented Jan 23, 2025

This simplifies agent boiler plate by allowing developers to only worry about their route logic. It covers generic Request/Response Types and returning valuable messages to end users on error (by responding with status 200 with error messages in the event that transaction is not created).

Example Usage in NextJs

safe agent deploy safe:

import { type NextRequest, NextResponse } from "next/server";
import {
  handleRequest,
  TxData,
  NULL_TRANSACTION,
  ...
} from "@bitteprotocol/agent-sdk";


async function logic(req: NextRequest): Promise<TxData> {
  // ... other logic involving request
  return {
    transaction: signRequestFor({
      chainId,
      metaTransactions: [NULL_TRANSACTION],
    }),
    meta: { safeUrl: safeUrl(safeAddress, chainId) },
  };
}

export async function GET(req: NextRequest): Promise<NextResponse> {
  return handleRequest(req, logic, (result) =>
    NextResponse.json(result, { status: 200 }),
  );
}

@bh2smith bh2smith merged commit b01de23 into main Jan 23, 2025
1 check passed
@bh2smith bh2smith deleted the generic-request-handler branch January 23, 2025 13:07
Copy link

@sainthiago sainthiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants