Skip to content

Commit e8d0976

Browse files
authored
Update datacallback response structure to wrap in request object (#201)
1 parent 743a825 commit e8d0976

2 files changed

Lines changed: 29 additions & 25 deletions

File tree

docs/base-account/examples/onchain-vibes-store-with-profiles.mdx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,16 @@ export async function POST(request: NextRequest) {
121121
if (Object.keys(errors).length > 0) {
122122
return NextResponse.json({ errors });
123123
}
124-
return NextResponse.json({
125-
calls: requestData.calls,
126-
chainId: requestData.chainId,
127-
capabilities: requestData.capabilities
128-
});
124+
// Return requestData wrapped in request object
125+
return NextResponse.json({ request: requestData });
129126
} catch (error) {
130127
return NextResponse.json({ errors: { server: "Server error validating data" } });
131128
}
132129
}
133130
```
134131

135132
- The API receives the user's data, validates it, and returns errors if needed.
136-
- If validation passes, it must return the original `calls`, `chainId`, and `capabilities`.
133+
- If validation passes, it must return the request data wrapped in a `request` object.
137134
- If errors are returned, the wallet prompts the user to correct their info.
138135

139136
---

docs/base-account/reference/core/capabilities/datacallback.mdx

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ Your callback API will receive a POST request with the following structure:
111111
data: string;
112112
}[];
113113
chainId: string;
114-
version: string;
115114
capabilities: {
116115
dataCallback: {
117116
requestedInfo: {
@@ -151,22 +150,23 @@ Your callback API must respond with one of two formats:
151150

152151
### 1. Success Response
153152

154-
Return the calls the user will end up submitting. They can be the same calls or new ones, but they must be present. You can change all capabilities (e.g. switching Paymaster if calls happen on a different chain) except the data callback capability, which must remain present.
153+
Return the calls the user will end up submitting wrapped in a `request` object. They can be the same calls or new ones, but they must be present. You can change all capabilities (e.g. switching Paymaster if calls happen on a different chain) except the data callback capability, which must remain present.
155154

156155
```typescript
157156
{
158-
calls: {
159-
to: string;
160-
data: string;
161-
}[];
162-
chainId: string;
163-
version: string;
164-
capabilities: {
165-
dataCallback: {
166-
// Original or updated dataCallback capability
157+
request: {
158+
calls: {
159+
to: string;
160+
data: string;
161+
}[];
162+
chainId: string;
163+
capabilities: {
164+
dataCallback: {
165+
// Original or updated dataCallback capability
166+
};
167+
// Other capabilities can be changed as needed
167168
};
168-
// Other capabilities can be changed as needed
169-
};
169+
}
170170
}
171171
```
172172

@@ -234,13 +234,20 @@ export async function POST(request: Request) {
234234
return Response.json({ errors });
235235
}
236236

237-
// Success - return original calls
238-
return Response.json({
239-
calls: requestData.calls,
240-
chainId: requestData.chainId,
241-
version: requestData.version,
242-
capabilities: requestData.capabilities
237+
// Success - return the request data wrapped in a request object
238+
// The wallet expects the response to contain the original or modified calls
239+
return Response.json({
240+
request: requestData
243241
});
242+
243+
// Alternative: Explicitly enumerate fields if needed
244+
// return Response.json({
245+
// request: {
246+
// calls: requestData.calls,
247+
// chainId: requestData.chainId,
248+
// capabilities: requestData.capabilities
249+
// }
250+
// });
244251

245252
} catch (error) {
246253
return Response.json({

0 commit comments

Comments
 (0)