Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-grapes-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Passed `chainId` to `wallet_getCapabilities`.
6 changes: 5 additions & 1 deletion src/actions/wallet/getCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<
Expand Down
8 changes: 4 additions & 4 deletions src/clients/decorators/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ export type WalletActions<
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* })
*/
getCapabilities: (
parameters?: GetCapabilitiesParameters,
) => Promise<GetCapabilitiesReturnType>
getCapabilities: <chainId extends number | undefined>(
parameters?: GetCapabilitiesParameters<chainId>,
) => Promise<GetCapabilitiesReturnType<chainId>>
/**
* Returns the chain ID associated with the current network.
*
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion src/types/eip1193.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WalletCapabilitiesRecord>
},
/**
Expand Down
Loading