Skip to content

Commit 1cbbbc3

Browse files
[SDK] Add EIP-5792 support to Coinbase and refactor wallet capabilities (#7732)
1 parent 58dbe90 commit 1cbbbc3

File tree

17 files changed

+992
-839
lines changed

17 files changed

+992
-839
lines changed

.changeset/early-queens-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Improve EIP5792 support

apps/playground-web/src/components/account-abstraction/5792-get-capabilities.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
useCapabilities,
77
useWalletInfo,
88
} from "thirdweb/react";
9-
import { createWallet } from "thirdweb/wallets";
9+
import { createWallet, inAppWallet } from "thirdweb/wallets";
1010
import { THIRDWEB_CLIENT } from "../../lib/client";
1111
import CodeClient from "../code/code.client";
1212

@@ -29,6 +29,12 @@ export function Eip5792GetCapabilitiesPreview() {
2929
label: "Login to view wallet capabilities",
3030
}}
3131
wallets={[
32+
inAppWallet({
33+
executionMode: {
34+
mode: "EIP7702",
35+
sponsorGas: true,
36+
},
37+
}),
3238
createWallet("io.metamask"),
3339
createWallet("com.coinbase.wallet"),
3440
]}

packages/thirdweb/src/wallets/coinbase/coinbase-web.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ import {
1414
stringToHex,
1515
uint8ArrayToHex,
1616
} from "../../utils/encoding/hex.js";
17+
import { stringify } from "../../utils/json.js";
1718
import { parseTypedData } from "../../utils/signatures/helpers/parse-typed-data.js";
1819
import { COINBASE } from "../constants.js";
20+
import { toGetCallsStatusResponse } from "../eip5792/get-calls-status.js";
21+
import { toGetCapabilitiesResult } from "../eip5792/get-capabilities.js";
22+
import { toProviderCallParams } from "../eip5792/send-calls.js";
23+
import type {
24+
GetCallsStatusRawResponse,
25+
WalletCapabilities,
26+
} from "../eip5792/types.js";
1927
import type {
2028
Account,
2129
SendTransactionOption,
@@ -269,6 +277,64 @@ function createAccount({
269277
}
270278
return res;
271279
},
280+
sendCalls: async (options) => {
281+
try {
282+
const { callParams, chain } = await toProviderCallParams(
283+
options,
284+
account,
285+
);
286+
const callId = await provider.request({
287+
method: "wallet_sendCalls",
288+
params: callParams,
289+
});
290+
if (callId && typeof callId === "object" && "id" in callId) {
291+
return { chain, client, id: callId.id as string };
292+
}
293+
return { chain, client, id: callId as string };
294+
} catch (error) {
295+
if (/unsupport|not support/i.test((error as Error).message)) {
296+
throw new Error(
297+
`${COINBASE} errored calling wallet_sendCalls, with error: ${error instanceof Error ? error.message : stringify(error)}`,
298+
);
299+
}
300+
throw error;
301+
}
302+
},
303+
async getCallsStatus(options) {
304+
try {
305+
const rawResponse = (await provider.request({
306+
method: "wallet_getCallsStatus",
307+
params: [options.id],
308+
})) as GetCallsStatusRawResponse;
309+
return toGetCallsStatusResponse(rawResponse);
310+
} catch (error) {
311+
if (/unsupport|not support/i.test((error as Error).message)) {
312+
throw new Error(
313+
`${COINBASE} does not support wallet_getCallsStatus, reach out to them directly to request EIP-5792 support.`,
314+
);
315+
}
316+
throw error;
317+
}
318+
},
319+
async getCapabilities(options) {
320+
const chainId = options.chainId;
321+
try {
322+
const result = (await provider.request({
323+
method: "wallet_getCapabilities",
324+
params: [getAddress(account.address)],
325+
})) as Record<string, WalletCapabilities>;
326+
return toGetCapabilitiesResult(result, chainId);
327+
} catch (error: unknown) {
328+
if (
329+
/unsupport|not support|not available/i.test((error as Error).message)
330+
) {
331+
return {
332+
message: `${COINBASE} does not support wallet_getCapabilities, reach out to them directly to request EIP-5792 support.`,
333+
};
334+
}
335+
throw error;
336+
}
337+
},
272338
};
273339

274340
return account;

0 commit comments

Comments
 (0)