@@ -14,8 +14,16 @@ import {
1414 stringToHex ,
1515 uint8ArrayToHex ,
1616} from "../../utils/encoding/hex.js" ;
17+ import { stringify } from "../../utils/json.js" ;
1718import { parseTypedData } from "../../utils/signatures/helpers/parse-typed-data.js" ;
1819import { 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" ;
1927import 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 ( / u n s u p p o r t | n o t s u p p o r t / 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 ( / u n s u p p o r t | n o t s u p p o r t / 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+ / u n s u p p o r t | n o t s u p p o r t | n o t a v a i l a b l e / 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