From 2823a67af230b16926ff2e30faefbfb238863cc3 Mon Sep 17 00:00:00 2001 From: jxom <7336481+jxom@users.noreply.github.com> Date: Fri, 2 May 2025 17:25:04 +1000 Subject: [PATCH] fix: `wallet_getCapabilities` params --- .changeset/breezy-grapes-appear.md | 5 +++++ src/actions/wallet/getCapabilities.ts | 6 +++++- src/clients/decorators/wallet.ts | 8 ++++---- src/types/eip1193.ts | 6 +++++- 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 .changeset/breezy-grapes-appear.md diff --git a/.changeset/breezy-grapes-appear.md b/.changeset/breezy-grapes-appear.md new file mode 100644 index 0000000000..ce0f50a141 --- /dev/null +++ b/.changeset/breezy-grapes-appear.md @@ -0,0 +1,5 @@ +--- +"viem": patch +--- + +Passed `chainId` to `wallet_getCapabilities`. diff --git a/src/actions/wallet/getCapabilities.ts b/src/actions/wallet/getCapabilities.ts index 6742593ccb..fc8786cdcd 100644 --- a/src/actions/wallet/getCapabilities.ts +++ b/src/actions/wallet/getCapabilities.ts @@ -11,6 +11,7 @@ import type { } from '../../types/eip1193.js' import type { Prettify } from '../../types/utils.js' import type { RequestErrorType } from '../../utils/buildRequest.js' +import { numberToHex } from '../../utils/encoding/toHex.js' export type GetCapabilitiesParameters< chainId extends number | undefined = undefined, @@ -59,9 +60,12 @@ export async function getCapabilities< const account_ = account ? parseAccount(account) : undefined + const params = chainId + ? ([account_?.address, [numberToHex(chainId)]] as const) + : ([account_?.address] as const) const capabilities_raw = await client.request({ method: 'wallet_getCapabilities', - params: [account_?.address], + params, }) const capabilities = {} as WalletCapabilitiesRecord< diff --git a/src/clients/decorators/wallet.ts b/src/clients/decorators/wallet.ts index bdbd876f53..5b7360fcd9 100644 --- a/src/clients/decorators/wallet.ts +++ b/src/clients/decorators/wallet.ts @@ -238,9 +238,9 @@ export type WalletActions< * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * }) */ - getCapabilities: ( - parameters?: GetCapabilitiesParameters, - ) => Promise + getCapabilities: ( + parameters?: GetCapabilitiesParameters, + ) => Promise> /** * Returns the chain ID associated with the current network. * @@ -963,7 +963,7 @@ export function walletActions< deployContract: (args) => deployContract(client, args), getAddresses: () => getAddresses(client), getCallsStatus: (args) => getCallsStatus(client, args), - getCapabilities: () => getCapabilities(client), + getCapabilities: (args) => getCapabilities(client, args), getChainId: () => getChainId(client), getPermissions: () => getPermissions(client), prepareAuthorization: (args) => prepareAuthorization(client, args), diff --git a/src/types/eip1193.ts b/src/types/eip1193.ts index e4d2496deb..b848e61abd 100644 --- a/src/types/eip1193.ts +++ b/src/types/eip1193.ts @@ -1795,7 +1795,11 @@ export type WalletRpcSchema = [ */ { Method: 'wallet_getCapabilities' - Parameters?: [Address | undefined] | undefined + Parameters?: + | readonly [] + | readonly [Address | undefined] + | readonly [Address | undefined, readonly Hex[] | undefined] + | undefined ReturnType: Prettify }, /**