WalletClientSigner

Defined in: aa-sdk/core/src/signer/wallet-client.ts:17

Represents a wallet client signer for smart accounts, providing methods to get the address, sign messages, and sign typed data.

Implements

  • unknown<WalletClient>

Constructors

Constructor

1new WalletClientSigner(client, signerType): WalletClientSigner;

Defined in: aa-sdk/core/src/signer/wallet-client.ts:42

Initializes a signer with a given wallet client and signer type.

Example

1import { WalletClientSigner } from "@aa-sdk/core";
2import { createWalletClient, custom } from "viem";
3import { mainnet } from "viem/chains";
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: custom(window.ethereum!),
8});
9
10const signer = new WalletClientSigner(client, "wallet");

Parameters

ParameterTypeDescription

client

{ account: undefined | Account; addChain: (args) => Promise<void>; batch?: { multicall?: | boolean | { batchSize?: number; wait?: number; }; }; cacheTime: number; ccipRead?: | false | { request?: (parameters) => Promise<`0x${string}`>; }; chain: undefined | Chain; deployContract: <abi, chainOverride>(args) => Promise<`0x${string}`>; experimental_blockTag?: BlockTag; extend: <client>(fn) => Client<Transport, undefined | Chain, undefined | Account, WalletRpcSchema, { [K in string | number | symbol]: client[K] } & WalletActions<undefined | Chain, undefined | Account>>; getAddresses: () => Promise<GetAddressesReturnType>; getCallsStatus: (parameters) => Promise<{ atomic: boolean; capabilities?: | { [key: string]: any; } | { [key: string]: any; }; chainId: number; id: string; receipts?: WalletCallReceipt<bigint, "success" | "reverted">[]; status: undefined | "pending" | "success" | "failure"; statusCode: number; version: string; }>; getCapabilities: <chainId>(parameters?) => Promise<{ [K in string | number | symbol]: (chainId extends number ? { atomic?: { status: “ready” | “supported” | “unsupported” }; paymasterService?: { supported: boolean }; unstable_addSubAccount?: { keyTypes: ((…) | (…) | (…) | (…))[]; supported: boolean }; [key: string]: any } : ChainIdToCapabilities<Capabilities<{ atomic?: { status: … }; paymasterService?: { supported: … }; unstable_addSubAccount?: { keyTypes: …; supported: … }; [key: string]: any }>, number>)[K] }>; getChainId: () => Promise<number>; getPermissions: () => Promise<GetPermissionsReturnType>; key: string; name: string; pollingInterval: number; prepareAuthorization: (parameters) => Promise<PrepareAuthorizationReturnType>; prepareTransactionRequest: <request, chainOverride, accountOverride>(args) => Promise<{ [K in string | number | symbol]: (UnionRequiredBy<Extract<UnionOmit<(…), (…)> & ((…) extends (…) ? (…) : (…)) & ((…) extends (…) ? (…) : (…)), IsNever<(…)> extends true ? unknown : ExactPartial<(…)>> & { chainId?: number }, ParameterTypeToParameters<request[“parameters”] extends readonly PrepareTransactionRequestParameterType[] ? any[any][number] : “type” | “gas” | “nonce” | “blobVersionedHashes” | “fees” | “chainId”>> & (unknown extends request[“kzg”] ? {} : Pick<request, “kzg”>))[K] }>; request: EIP1193RequestFn<WalletRpcSchema>; requestAddresses: () => Promise<RequestAddressesReturnType>; requestPermissions: (args) => Promise<RequestPermissionsReturnType>; sendCalls: <calls, chainOverride>(parameters) => Promise<{ capabilities?: { [key: string]: any; }; id: string; }>; sendRawTransaction: (args) => Promise<`0x${string}`>; sendTransaction: <request, chainOverride>(args) => Promise<`0x${string}`>; showCallsStatus: (parameters) => Promise<void>; signAuthorization: (parameters) => Promise<SignAuthorizationReturnType>; signMessage: (args) => Promise<`0x${string}`>; signTransaction: <chainOverride, request>(args) => Promise<TransactionSerialized<GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never>, | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip1559" ? `0x02${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip2930" ? `0x01${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip4844" ? `0x03${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip7702" ? `0x04${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "legacy" ? TransactionSerializedLegacy : never>>; signTypedData: <typedData, primaryType>(args) => Promise<`0x${string}`>; switchChain: (args) => Promise<void>; transport: TransportConfig<string, EIP1193RequestFn> & Record<string, any>; type: string; uid: string; waitForCallsStatus: (parameters) => Promise<{ atomic: boolean; capabilities?: | { [key: string]: any; } | { [key: string]: any; }; chainId: number; id: string; receipts?: WalletCallReceipt<bigint, "success" | "reverted">[]; status: undefined | "pending" | "success" | "failure"; statusCode: number; version: string; }>; watchAsset: (args) => Promise<boolean>; writeContract: <abi, functionName, args, chainOverride>(args) => Promise<`0x${string}`>; }

The wallet client to interact with

client.account

undefined | Account

The Account of the Client.

client.addChain

(args) => Promise<void>

Adds an EVM chain to the wallet.

Example

1import { createWalletClient, custom } from 'viem'
2import { optimism } from 'viem/chains'
3
4const client = createWalletClient({
5 transport: custom(window.ethereum),
6})
7await client.addChain({ chain: optimism })

client.batch?

{ multicall?: | boolean | { batchSize?: number; wait?: number; }; }

Flags for batch settings.

client.batch.multicall?

| boolean | { batchSize?: number; wait?: number; }

Toggle to enable eth_call multicall aggregation.

client.cacheTime

number

Time (in ms) that cached data will remain in memory.

client.ccipRead?

| false | { request?: (parameters) => Promise<`0x${string}`>; }

CCIP Read configuration.

client.chain

undefined | Chain

Chain for the client.

client.deployContract

<abi, chainOverride>(args) => Promise<`0x${string}`>

Deploys a contract to the network, given bytecode and constructor arguments.

Example

1import { createWalletClient, http } from 'viem'
2import { privateKeyToAccount } from 'viem/accounts'
3import { mainnet } from 'viem/chains'
4
5const client = createWalletClient({
6 account: privateKeyToAccount('0x…'),
7 chain: mainnet,
8 transport: http(),
9})
10const hash = await client.deployContract({
11 abi: [],
12 account: '0x…,
13 bytecode: '0x608060405260405161083e38038061083e833981016040819052610...',
14})

client.experimental_blockTag?

BlockTag

Default block tag to use for RPC requests.

client.extend

<client>(fn) => Client<Transport, undefined | Chain, undefined | Account, WalletRpcSchema, { [K in string | number | symbol]: client[K] } & WalletActions<undefined | Chain, undefined | Account>>

client.getAddresses

() => Promise<GetAddressesReturnType>

Returns a list of account addresses owned by the wallet or client.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const accounts = await client.getAddresses()

client.getCallsStatus

(parameters) => Promise<{ atomic: boolean; capabilities?: | { [key: string]: any; } | { [key: string]: any; }; chainId: number; id: string; receipts?: WalletCallReceipt<bigint, "success" | "reverted">[]; status: undefined | "pending" | "success" | "failure"; statusCode: number; version: string; }>

Returns the status of a call batch that was sent via sendCalls.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8
9const { receipts, status } = await client.getCallsStatus({ id: '0xdeadbeef' })

client.getCapabilities

<chainId>(parameters?) => Promise<{ [K in string | number | symbol]: (chainId extends number ? { atomic?: { status: “ready” | “supported” | “unsupported” }; paymasterService?: { supported: boolean }; unstable_addSubAccount?: { keyTypes: ((…) | (…) | (…) | (…))[]; supported: boolean }; [key: string]: any } : ChainIdToCapabilities<Capabilities<{ atomic?: { status: … }; paymasterService?: { supported: … }; unstable_addSubAccount?: { keyTypes: …; supported: … }; [key: string]: any }>, number>)[K] }>

Extract capabilities that a connected wallet supports (e.g. paymasters, session keys, etc).

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8
9const capabilities = await client.getCapabilities({
10 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
11})

client.getChainId

() => Promise<number>

Returns the chain ID associated with the current network.

Example

1import { createWalletClient, http } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const chainId = await client.getChainId()
9// 1

client.getPermissions

() => Promise<GetPermissionsReturnType>

Gets the wallets current permissions.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const permissions = await client.getPermissions()

client.key

string

A key for the client.

client.name

string

A name for the client.

client.pollingInterval

number

Frequency (in ms) for polling enabled actions & events. Defaults to 4_000 milliseconds.

client.prepareAuthorization

(parameters) => Promise<PrepareAuthorizationReturnType>

Prepares an EIP-7702 Authorization object for signing. This Action will fill the required fields of the Authorization object if they are not provided (e.g. nonce and chainId).

With the prepared Authorization object, you can use signAuthorization to sign over the Authorization object.

Examples

1import { createWalletClient, http } from 'viem'
2import { privateKeyToAccount } from 'viem/accounts'
3import { mainnet } from 'viem/chains'
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: http(),
8})
9
10const authorization = await client.prepareAuthorization({
11 account: privateKeyToAccount('0x..'),
12 contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
13})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: http(),
10})
11
12const authorization = await client.prepareAuthorization({
13 contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
14})

client.prepareTransactionRequest

<request, chainOverride, accountOverride>(args) => Promise<{ [K in string | number | symbol]: (UnionRequiredBy<Extract<UnionOmit<(…), (…)> & ((…) extends (…) ? (…) : (…)) & ((…) extends (…) ? (…) : (…)), IsNever<(…)> extends true ? unknown : ExactPartial<(…)>> & { chainId?: number }, ParameterTypeToParameters<request[“parameters”] extends readonly PrepareTransactionRequestParameterType[] ? any[any][number] : “type” | “gas” | “nonce” | “blobVersionedHashes” | “fees” | “chainId”>> & (unknown extends request[“kzg”] ? {} : Pick<request, “kzg”>))[K] }>

Prepares a transaction request for signing.

Examples

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const request = await client.prepareTransactionRequest({
9 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
10 to: '0x0000000000000000000000000000000000000000',
11 value: 1n,
12})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: custom(window.ethereum),
10})
11const request = await client.prepareTransactionRequest({
12 to: '0x0000000000000000000000000000000000000000',
13 value: 1n,
14})

client.request

EIP1193RequestFn<WalletRpcSchema>

Request function wrapped with friendly error handling

client.requestAddresses

() => Promise<RequestAddressesReturnType>

Requests a list of accounts managed by a wallet.

Sends a request to the wallet, asking for permission to access the user’s accounts. After the user accepts the request, it will return a list of accounts (addresses).

This API can be useful for dapps that need to access the user’s accounts in order to execute transactions or interact with smart contracts.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const accounts = await client.requestAddresses()

client.requestPermissions

(args) => Promise<RequestPermissionsReturnType>

Requests permissions for a wallet.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const permissions = await client.requestPermissions({
9 eth_accounts: {}
10})

client.sendCalls

<calls, chainOverride>(parameters) => Promise<{ capabilities?: { [key: string]: any; }; id: string; }>

Requests the connected wallet to send a batch of calls.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8
9const id = await client.sendCalls({
10 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
11 calls: [
12 {
13 data: '0xdeadbeef',
14 to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
15 },
16 {
17 to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
18 value: 69420n,
19 },
20 ],
21})

client.sendRawTransaction

(args) => Promise<`0x${string}`>

Sends a signed transaction to the network

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3import { sendRawTransaction } from 'viem/wallet'
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: custom(window.ethereum),
8})
9
10const hash = await client.sendRawTransaction({
11 serializedTransaction: '0x02f850018203118080825208808080c080a04012522854168b27e5dc3d5839bab5e6b39e1a0ffd343901ce1622e3d64b48f1a04e00902ae0502c4728cbf12156290df99c3ed7de85b1dbfe20b5c36931733a33'
12})

client.sendTransaction

<request, chainOverride>(args) => Promise<`0x${string}`>

Creates, signs, and sends a new transaction to the network.

Examples

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const hash = await client.sendTransaction({
9 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
10 to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
11 value: 1000000000000000000n,
12})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: http(),
10})
11const hash = await client.sendTransaction({
12 to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
13 value: 1000000000000000000n,
14})

client.showCallsStatus

(parameters) => Promise<void>

Requests for the wallet to show information about a call batch that was sent via sendCalls.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8
9await client.showCallsStatus({ id: '0xdeadbeef' })

client.signAuthorization

(parameters) => Promise<SignAuthorizationReturnType>

Signs an EIP-7702 Authorization object.

With the calculated signature, you can:

Examples

1import { createWalletClient, http } from 'viem'
2import { privateKeyToAccount } from 'viem/accounts'
3import { mainnet } from 'viem/chains'
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: http(),
8})
9
10const signature = await client.signAuthorization({
11 account: privateKeyToAccount('0x..'),
12 contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
13})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: http(),
10})
11
12const signature = await client.signAuthorization({
13 contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
14})

client.signMessage

(args) => Promise<`0x${string}`>

Calculates an Ethereum-specific signature in EIP-191 format: keccak256("\x19Ethereum Signed Message:\n" + len(message) + message)).

With the calculated signature, you can:

Examples

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const signature = await client.signMessage({
9 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
10 message: 'hello world',
11})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: http(),
10})
11const signature = await client.signMessage({
12 message: 'hello world',
13})

client.signTransaction

<chainOverride, request>(args) => Promise<TransactionSerialized<GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never>, | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip1559" ? `0x02${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip2930" ? `0x01${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip4844" ? `0x03${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip7702" ? `0x04${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "legacy" ? TransactionSerializedLegacy : never>>

Signs a transaction.

Examples

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const request = await client.prepareTransactionRequest({
9 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
10 to: '0x0000000000000000000000000000000000000000',
11 value: 1n,
12})
13const signature = await client.signTransaction(request)
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: custom(window.ethereum),
10})
11const request = await client.prepareTransactionRequest({
12 to: '0x0000000000000000000000000000000000000000',
13 value: 1n,
14})
15const signature = await client.signTransaction(request)

client.signTypedData

<typedData, primaryType>(args) => Promise<`0x${string}`>

Signs typed data and calculates an Ethereum-specific signature in EIP-191 format: keccak256("\x19Ethereum Signed Message:\n" + len(message) + message)).

Examples

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const signature = await client.signTypedData({
9 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
10 domain: {
11 name: 'Ether Mail',
12 version: '1',
13 chainId: 1,
14 verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
15 },
16 types: {
17 Person: [
18 { name: 'name', type: 'string' },
19 { name: 'wallet', type: 'address' },
20 ],
21 Mail: [
22 { name: 'from', type: 'Person' },
23 { name: 'to', type: 'Person' },
24 { name: 'contents', type: 'string' },
25 ],
26 },
27 primaryType: 'Mail',
28 message: {
29 from: {
30 name: 'Cow',
31 wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
32 },
33 to: {
34 name: 'Bob',
35 wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
36 },
37 contents: 'Hello, Bob!',
38 },
39})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: http(),
10})
11const signature = await client.signTypedData({
12 domain: {
13 name: 'Ether Mail',
14 version: '1',
15 chainId: 1,
16 verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
17 },
18 types: {
19 Person: [
20 { name: 'name', type: 'string' },
21 { name: 'wallet', type: 'address' },
22 ],
23 Mail: [
24 { name: 'from', type: 'Person' },
25 { name: 'to', type: 'Person' },
26 { name: 'contents', type: 'string' },
27 ],
28 },
29 primaryType: 'Mail',
30 message: {
31 from: {
32 name: 'Cow',
33 wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
34 },
35 to: {
36 name: 'Bob',
37 wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
38 },
39 contents: 'Hello, Bob!',
40 },
41})

client.switchChain

(args) => Promise<void>

Switch the target chain in a wallet.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet, optimism } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8await client.switchChain({ id: optimism.id })

client.transport

TransportConfig<string, EIP1193RequestFn> & Record<string, any>

The RPC transport

client.type

string

The type of client.

client.uid

string

A unique ID for the client.

client.waitForCallsStatus

(parameters) => Promise<{ atomic: boolean; capabilities?: | { [key: string]: any; } | { [key: string]: any; }; chainId: number; id: string; receipts?: WalletCallReceipt<bigint, "success" | "reverted">[]; status: undefined | "pending" | "success" | "failure"; statusCode: number; version: string; }>

Waits for the status & receipts of a call bundle that was sent via sendCalls.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8
9const { receipts, status } = await waitForCallsStatus(client, { id: '0xdeadbeef' })

client.watchAsset

(args) => Promise<boolean>

Adds an EVM chain to the wallet.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const success = await client.watchAsset({
9 type: 'ERC20',
10 options: {
11 address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
12 decimals: 18,
13 symbol: 'WETH',
14 },
15})

client.writeContract

<abi, functionName, args, chainOverride>(args) => Promise<`0x${string}`>

Executes a write function on a contract.

A “write” function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a Transaction is needed to be broadcast in order to change the state.

Internally, uses a Wallet Client to call the sendTransaction action with ABI-encoded data.

Warning: The write internally sends a transaction – it does not validate if the contract write will succeed (the contract may throw an error). It is highly recommended to simulate the contract write with contract.simulate before you execute it.

Examples

1import { createWalletClient, custom, parseAbi } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const hash = await client.writeContract({
9 address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
10 abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
11 functionName: 'mint',
12 args: [69420],
13})
1// With Validation
2import { createWalletClient, custom, parseAbi } from 'viem'
3import { mainnet } from 'viem/chains'
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: custom(window.ethereum),
8})
9const { request } = await client.simulateContract({
10 address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
11 abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
12 functionName: 'mint',
13 args: [69420],
14}
15const hash = await client.writeContract(request)

signerType

string

The type of signer; must be a valid signer type, otherwise an error will be thrown

Returns

WalletClientSigner

Throws

If the signer type is invalid

Properties

PropertyTypeDescription

getAddress

() => Promise<`0x${string}`>

Asynchronously retrieves addresses from the inner object and returns the first address after applying the getAddress function.

Example

1import { WalletClientSigner } from "@aa-sdk/core";
2import { createWalletClient, custom } from 'viem'
3import { mainnet } from 'viem/chains'
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: custom(window.ethereum!)
8});
9
10const signer = new WalletClientSigner(client, 'wallet');
11console.log(await signer.getAddress());

inner

object

inner.account

undefined | Account

The Account of the Client.

inner.addChain

(args) => Promise<void>

Adds an EVM chain to the wallet.

Example

1import { createWalletClient, custom } from 'viem'
2import { optimism } from 'viem/chains'
3
4const client = createWalletClient({
5 transport: custom(window.ethereum),
6})
7await client.addChain({ chain: optimism })

inner.batch?

object

Flags for batch settings.

inner.batch.multicall?

| boolean | { batchSize?: number; wait?: number; }

Toggle to enable eth_call multicall aggregation.

inner.cacheTime

number

Time (in ms) that cached data will remain in memory.

inner.ccipRead?

| false | { request?: (parameters) => Promise<`0x${string}`>; }

CCIP Read configuration.

inner.chain

undefined | Chain

Chain for the client.

inner.deployContract

<abi, chainOverride>(args) => Promise<`0x${string}`>

Deploys a contract to the network, given bytecode and constructor arguments.

Example

1import { createWalletClient, http } from 'viem'
2import { privateKeyToAccount } from 'viem/accounts'
3import { mainnet } from 'viem/chains'
4
5const client = createWalletClient({
6 account: privateKeyToAccount('0x…'),
7 chain: mainnet,
8 transport: http(),
9})
10const hash = await client.deployContract({
11 abi: [],
12 account: '0x…,
13 bytecode: '0x608060405260405161083e38038061083e833981016040819052610...',
14})

inner.experimental_blockTag?

BlockTag

Default block tag to use for RPC requests.

inner.extend

<client>(fn) => Client<Transport, undefined | Chain, undefined | Account, WalletRpcSchema, { [K in string | number | symbol]: client[K] } & WalletActions<undefined | Chain, undefined | Account>>

inner.getAddresses

() => Promise<GetAddressesReturnType>

Returns a list of account addresses owned by the wallet or client.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const accounts = await client.getAddresses()

inner.getCallsStatus

(parameters) => Promise<{ atomic: boolean; capabilities?: | { [key: string]: any; } | { [key: string]: any; }; chainId: number; id: string; receipts?: WalletCallReceipt<bigint, "success" | "reverted">[]; status: undefined | "pending" | "success" | "failure"; statusCode: number; version: string; }>

Returns the status of a call batch that was sent via sendCalls.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8
9const { receipts, status } = await client.getCallsStatus({ id: '0xdeadbeef' })

inner.getCapabilities

<chainId>(parameters?) => Promise<{ [K in string | number | symbol]: (chainId extends number ? { atomic?: { status: “ready” | “supported” | “unsupported” }; paymasterService?: { supported: boolean }; unstable_addSubAccount?: { keyTypes: ((…) | (…) | (…) | (…))[]; supported: boolean }; [key: string]: any } : ChainIdToCapabilities<Capabilities<{ atomic?: { status: … }; paymasterService?: { supported: … }; unstable_addSubAccount?: { keyTypes: …; supported: … }; [key: string]: any }>, number>)[K] }>

Extract capabilities that a connected wallet supports (e.g. paymasters, session keys, etc).

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8
9const capabilities = await client.getCapabilities({
10 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
11})

inner.getChainId

() => Promise<number>

Returns the chain ID associated with the current network.

Example

1import { createWalletClient, http } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const chainId = await client.getChainId()
9// 1

inner.getPermissions

() => Promise<GetPermissionsReturnType>

Gets the wallets current permissions.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const permissions = await client.getPermissions()

inner.key

string

A key for the client.

inner.name

string

A name for the client.

inner.pollingInterval

number

Frequency (in ms) for polling enabled actions & events. Defaults to 4_000 milliseconds.

inner.prepareAuthorization

(parameters) => Promise<PrepareAuthorizationReturnType>

Prepares an EIP-7702 Authorization object for signing. This Action will fill the required fields of the Authorization object if they are not provided (e.g. nonce and chainId).

With the prepared Authorization object, you can use signAuthorization to sign over the Authorization object.

Examples

1import { createWalletClient, http } from 'viem'
2import { privateKeyToAccount } from 'viem/accounts'
3import { mainnet } from 'viem/chains'
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: http(),
8})
9
10const authorization = await client.prepareAuthorization({
11 account: privateKeyToAccount('0x..'),
12 contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
13})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: http(),
10})
11
12const authorization = await client.prepareAuthorization({
13 contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
14})

inner.prepareTransactionRequest

<request, chainOverride, accountOverride>(args) => Promise<{ [K in string | number | symbol]: (UnionRequiredBy<Extract<UnionOmit<(…), (…)> & ((…) extends (…) ? (…) : (…)) & ((…) extends (…) ? (…) : (…)), IsNever<(…)> extends true ? unknown : ExactPartial<(…)>> & { chainId?: number }, ParameterTypeToParameters<request[“parameters”] extends readonly PrepareTransactionRequestParameterType[] ? any[any][number] : “type” | “gas” | “nonce” | “blobVersionedHashes” | “fees” | “chainId”>> & (unknown extends request[“kzg”] ? {} : Pick<request, “kzg”>))[K] }>

Prepares a transaction request for signing.

Examples

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const request = await client.prepareTransactionRequest({
9 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
10 to: '0x0000000000000000000000000000000000000000',
11 value: 1n,
12})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: custom(window.ethereum),
10})
11const request = await client.prepareTransactionRequest({
12 to: '0x0000000000000000000000000000000000000000',
13 value: 1n,
14})

inner.request

EIP1193RequestFn<WalletRpcSchema>

Request function wrapped with friendly error handling

inner.requestAddresses

() => Promise<RequestAddressesReturnType>

Requests a list of accounts managed by a wallet.

Sends a request to the wallet, asking for permission to access the user’s accounts. After the user accepts the request, it will return a list of accounts (addresses).

This API can be useful for dapps that need to access the user’s accounts in order to execute transactions or interact with smart contracts.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const accounts = await client.requestAddresses()

inner.requestPermissions

(args) => Promise<RequestPermissionsReturnType>

Requests permissions for a wallet.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const permissions = await client.requestPermissions({
9 eth_accounts: {}
10})

inner.sendCalls

<calls, chainOverride>(parameters) => Promise<{ capabilities?: { [key: string]: any; }; id: string; }>

Requests the connected wallet to send a batch of calls.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8
9const id = await client.sendCalls({
10 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
11 calls: [
12 {
13 data: '0xdeadbeef',
14 to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
15 },
16 {
17 to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
18 value: 69420n,
19 },
20 ],
21})

inner.sendRawTransaction

(args) => Promise<`0x${string}`>

Sends a signed transaction to the network

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3import { sendRawTransaction } from 'viem/wallet'
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: custom(window.ethereum),
8})
9
10const hash = await client.sendRawTransaction({
11 serializedTransaction: '0x02f850018203118080825208808080c080a04012522854168b27e5dc3d5839bab5e6b39e1a0ffd343901ce1622e3d64b48f1a04e00902ae0502c4728cbf12156290df99c3ed7de85b1dbfe20b5c36931733a33'
12})

inner.sendTransaction

<request, chainOverride>(args) => Promise<`0x${string}`>

Creates, signs, and sends a new transaction to the network.

Examples

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const hash = await client.sendTransaction({
9 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
10 to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
11 value: 1000000000000000000n,
12})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: http(),
10})
11const hash = await client.sendTransaction({
12 to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
13 value: 1000000000000000000n,
14})

inner.showCallsStatus

(parameters) => Promise<void>

Requests for the wallet to show information about a call batch that was sent via sendCalls.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8
9await client.showCallsStatus({ id: '0xdeadbeef' })

inner.signAuthorization

(parameters) => Promise<SignAuthorizationReturnType>

Signs an EIP-7702 Authorization object.

With the calculated signature, you can:

Examples

1import { createWalletClient, http } from 'viem'
2import { privateKeyToAccount } from 'viem/accounts'
3import { mainnet } from 'viem/chains'
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: http(),
8})
9
10const signature = await client.signAuthorization({
11 account: privateKeyToAccount('0x..'),
12 contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
13})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: http(),
10})
11
12const signature = await client.signAuthorization({
13 contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
14})

inner.signMessage

(args) => Promise<`0x${string}`>

Calculates an Ethereum-specific signature in EIP-191 format: keccak256("\x19Ethereum Signed Message:\n" + len(message) + message)).

With the calculated signature, you can:

Examples

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const signature = await client.signMessage({
9 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
10 message: 'hello world',
11})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: http(),
10})
11const signature = await client.signMessage({
12 message: 'hello world',
13})

inner.signTransaction

<chainOverride, request>(args) => Promise<TransactionSerialized<GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never>, | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip1559" ? `0x02${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip2930" ? `0x01${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip4844" ? `0x03${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "eip7702" ? `0x04${string}` : never | GetTransactionType<request, | request extends LegacyProperties ? "legacy" : never | request extends EIP1559Properties ? "eip1559" : never | request extends EIP2930Properties ? "eip2930" : never | request extends EIP4844Properties ? "eip4844" : never | request extends EIP7702Properties ? "eip7702" : never | request["type"] extends undefined | string ? Extract<any[any], string> : never> extends "legacy" ? TransactionSerializedLegacy : never>>

Signs a transaction.

Examples

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const request = await client.prepareTransactionRequest({
9 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
10 to: '0x0000000000000000000000000000000000000000',
11 value: 1n,
12})
13const signature = await client.signTransaction(request)
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: custom(window.ethereum),
10})
11const request = await client.prepareTransactionRequest({
12 to: '0x0000000000000000000000000000000000000000',
13 value: 1n,
14})
15const signature = await client.signTransaction(request)

inner.signTypedData

<typedData, primaryType>(args) => Promise<`0x${string}`>

Signs typed data and calculates an Ethereum-specific signature in EIP-191 format: keccak256("\x19Ethereum Signed Message:\n" + len(message) + message)).

Examples

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const signature = await client.signTypedData({
9 account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
10 domain: {
11 name: 'Ether Mail',
12 version: '1',
13 chainId: 1,
14 verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
15 },
16 types: {
17 Person: [
18 { name: 'name', type: 'string' },
19 { name: 'wallet', type: 'address' },
20 ],
21 Mail: [
22 { name: 'from', type: 'Person' },
23 { name: 'to', type: 'Person' },
24 { name: 'contents', type: 'string' },
25 ],
26 },
27 primaryType: 'Mail',
28 message: {
29 from: {
30 name: 'Cow',
31 wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
32 },
33 to: {
34 name: 'Bob',
35 wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
36 },
37 contents: 'Hello, Bob!',
38 },
39})
1// Account Hoisting
2import { createWalletClient, http } from 'viem'
3import { privateKeyToAccount } from 'viem/accounts'
4import { mainnet } from 'viem/chains'
5
6const client = createWalletClient({
7 account: privateKeyToAccount('0x…'),
8 chain: mainnet,
9 transport: http(),
10})
11const signature = await client.signTypedData({
12 domain: {
13 name: 'Ether Mail',
14 version: '1',
15 chainId: 1,
16 verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
17 },
18 types: {
19 Person: [
20 { name: 'name', type: 'string' },
21 { name: 'wallet', type: 'address' },
22 ],
23 Mail: [
24 { name: 'from', type: 'Person' },
25 { name: 'to', type: 'Person' },
26 { name: 'contents', type: 'string' },
27 ],
28 },
29 primaryType: 'Mail',
30 message: {
31 from: {
32 name: 'Cow',
33 wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
34 },
35 to: {
36 name: 'Bob',
37 wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
38 },
39 contents: 'Hello, Bob!',
40 },
41})

inner.switchChain

(args) => Promise<void>

Switch the target chain in a wallet.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet, optimism } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8await client.switchChain({ id: optimism.id })

inner.transport

TransportConfig<string, EIP1193RequestFn> & Record<string, any>

The RPC transport

inner.type

string

The type of client.

inner.uid

string

A unique ID for the client.

inner.waitForCallsStatus

(parameters) => Promise<{ atomic: boolean; capabilities?: | { [key: string]: any; } | { [key: string]: any; }; chainId: number; id: string; receipts?: WalletCallReceipt<bigint, "success" | "reverted">[]; status: undefined | "pending" | "success" | "failure"; statusCode: number; version: string; }>

Waits for the status & receipts of a call bundle that was sent via sendCalls.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8
9const { receipts, status } = await waitForCallsStatus(client, { id: '0xdeadbeef' })

inner.watchAsset

(args) => Promise<boolean>

Adds an EVM chain to the wallet.

Example

1import { createWalletClient, custom } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const success = await client.watchAsset({
9 type: 'ERC20',
10 options: {
11 address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
12 decimals: 18,
13 symbol: 'WETH',
14 },
15})

inner.writeContract

<abi, functionName, args, chainOverride>(args) => Promise<`0x${string}`>

Executes a write function on a contract.

A “write” function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a Transaction is needed to be broadcast in order to change the state.

Internally, uses a Wallet Client to call the sendTransaction action with ABI-encoded data.

Warning: The write internally sends a transaction – it does not validate if the contract write will succeed (the contract may throw an error). It is highly recommended to simulate the contract write with contract.simulate before you execute it.

Examples

1import { createWalletClient, custom, parseAbi } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createWalletClient({
5 chain: mainnet,
6 transport: custom(window.ethereum),
7})
8const hash = await client.writeContract({
9 address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
10 abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
11 functionName: 'mint',
12 args: [69420],
13})
1// With Validation
2import { createWalletClient, custom, parseAbi } from 'viem'
3import { mainnet } from 'viem/chains'
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: custom(window.ethereum),
8})
9const { request } = await client.simulateContract({
10 address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
11 abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
12 functionName: 'mint',
13 args: [69420],
14}
15const hash = await client.writeContract(request)

signerType

string

signMessage

(message) => Promise<`0x${string}`>

Signs a message using the account’s signing method.

Example

1import { WalletClientSigner } from "@aa-sdk/core";
2import { createWalletClient, custom } from 'viem'
3import { mainnet } from 'viem/chains'
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: custom(window.ethereum!)
8});
9
10const signer = new WalletClientSigner(client, 'wallet');
11console.log(await signer.signMessage("hello"));

Methods

signTypedData()

1signTypedData<TTypedData, TPrimaryType>(typedData): Promise<`0x${string}`>;

Defined in: aa-sdk/core/src/signer/wallet-client.ts:130

Signs the provided typed data using the account’s private key.

Example

1import { WalletClientSigner } from "@aa-sdk/core";
2import { createWalletClient, custom } from "viem";
3import { mainnet } from "viem/chains";
4
5const client = createWalletClient({
6 chain: mainnet,
7 transport: custom(window.ethereum!),
8});
9
10const signer = new WalletClientSigner(client, "wallet");
11console.log(
12 await signer.signTypedData({
13 types: {
14 Message: [{ name: "content", type: "string" }],
15 },
16 primaryType: "Message",
17 message: { content: "Hello" },
18 }),
19);

Type Parameters

Type ParameterDefault type

TTypedData extends | { [key: string]: readonly TypedDataParameter[]; [key: `string[${string}]`]: undefined; [key: `function[${string}]`]: undefined; [key: `address[${string}]`]: undefined; [key: `bool[${string}]`]: undefined; [key: `bytes[${string}]`]: undefined; [key: `bytes1[${string}]`]: undefined; [key: `bytes2[${string}]`]: undefined; [key: `bytes3[${string}]`]: undefined; [key: `bytes4[${string}]`]: undefined; [key: `bytes5[${string}]`]: undefined; [key: `bytes6[${string}]`]: undefined; [key: `bytes7[${string}]`]: undefined; [key: `bytes8[${string}]`]: undefined; [key: `bytes9[${string}]`]: undefined; [key: `bytes10[${string}]`]: undefined; [key: `bytes11[${string}]`]: undefined; [key: `bytes12[${string}]`]: undefined; [key: `bytes13[${string}]`]: undefined; [key: `bytes14[${string}]`]: undefined; [key: `bytes15[${string}]`]: undefined; [key: `bytes16[${string}]`]: undefined; [key: `bytes17[${string}]`]: undefined; [key: `bytes18[${string}]`]: undefined; [key: `bytes19[${string}]`]: undefined; [key: `bytes20[${string}]`]: undefined; [key: `bytes21[${string}]`]: undefined; [key: `bytes22[${string}]`]: undefined; [key: `bytes23[${string}]`]: undefined; [key: `bytes24[${string}]`]: undefined; [key: `bytes25[${string}]`]: undefined; [key: `bytes26[${string}]`]: undefined; [key: `bytes27[${string}]`]: undefined; [key: `bytes28[${string}]`]: undefined; [key: `bytes29[${string}]`]: undefined; [key: `bytes30[${string}]`]: undefined; [key: `bytes31[${string}]`]: undefined; [key: `bytes32[${string}]`]: undefined; [key: `int[${string}]`]: undefined; [key: `int8[${string}]`]: undefined; [key: `int16[${string}]`]: undefined; [key: `int24[${string}]`]: undefined; [key: `int32[${string}]`]: undefined; [key: `int40[${string}]`]: undefined; [key: `int48[${string}]`]: undefined; [key: `int56[${string}]`]: undefined; [key: `int64[${string}]`]: undefined; [key: `int72[${string}]`]: undefined; [key: `int80[${string}]`]: undefined; [key: `int88[${string}]`]: undefined; [key: `int96[${string}]`]: undefined; [key: `int104[${string}]`]: undefined; [key: `int112[${string}]`]: undefined; [key: `int120[${string}]`]: undefined; [key: `int128[${string}]`]: undefined; [key: `int136[${string}]`]: undefined; [key: `int144[${string}]`]: undefined; [key: `int152[${string}]`]: undefined; [key: `int160[${string}]`]: undefined; [key: `int168[${string}]`]: undefined; [key: `int176[${string}]`]: undefined; [key: `int184[${string}]`]: undefined; [key: `int192[${string}]`]: undefined; [key: `int200[${string}]`]: undefined; [key: `int208[${string}]`]: undefined; [key: `int216[${string}]`]: undefined; [key: `int224[${string}]`]: undefined; [key: `int232[${string}]`]: undefined; [key: `int240[${string}]`]: undefined; [key: `int248[${string}]`]: undefined; [key: `int256[${string}]`]: undefined; [key: `uint[${string}]`]: undefined; [key: `uint8[${string}]`]: undefined; [key: `uint16[${string}]`]: undefined; [key: `uint24[${string}]`]: undefined; [key: `uint32[${string}]`]: undefined; [key: `uint40[${string}]`]: undefined; [key: `uint48[${string}]`]: undefined; [key: `uint56[${string}]`]: undefined; [key: `uint64[${string}]`]: undefined; [key: `uint72[${string}]`]: undefined; [key: `uint80[${string}]`]: undefined; [key: `uint88[${string}]`]: undefined; [key: `uint96[${string}]`]: undefined; [key: `uint104[${string}]`]: undefined; [key: `uint112[${string}]`]: undefined; [key: `uint120[${string}]`]: undefined; [key: `uint128[${string}]`]: undefined; [key: `uint136[${string}]`]: undefined; [key: `uint144[${string}]`]: undefined; [key: `uint152[${string}]`]: undefined; [key: `uint160[${string}]`]: undefined; [key: `uint168[${string}]`]: undefined; [key: `uint176[${string}]`]: undefined; [key: `uint184[${string}]`]: undefined; [key: `uint192[${string}]`]: undefined; [key: `uint200[${string}]`]: undefined; [key: `uint208[${string}]`]: undefined; [key: `uint216[${string}]`]: undefined; [key: `uint224[${string}]`]: undefined; [key: `uint232[${string}]`]: undefined; [key: `uint240[${string}]`]: undefined; [key: `uint248[${string}]`]: undefined; [key: `uint256[${string}]`]: undefined; address?: undefined; bool?: undefined; bytes?: undefined; bytes1?: undefined; bytes10?: undefined; bytes11?: undefined; bytes12?: undefined; bytes13?: undefined; bytes14?: undefined; bytes15?: undefined; bytes16?: undefined; bytes17?: undefined; bytes18?: undefined; bytes19?: undefined; bytes2?: undefined; bytes20?: undefined; bytes21?: undefined; bytes22?: undefined; bytes23?: undefined; bytes24?: undefined; bytes25?: undefined; bytes26?: undefined; bytes27?: undefined; bytes28?: undefined; bytes29?: undefined; bytes3?: undefined; bytes30?: undefined; bytes31?: undefined; bytes32?: undefined; bytes4?: undefined; bytes5?: undefined; bytes6?: undefined; bytes7?: undefined; bytes8?: undefined; bytes9?: undefined; int104?: undefined; int112?: undefined; int120?: undefined; int128?: undefined; int136?: undefined; int144?: undefined; int152?: undefined; int16?: undefined; int160?: undefined; int168?: undefined; int176?: undefined; int184?: undefined; int192?: undefined; int200?: undefined; int208?: undefined; int216?: undefined; int224?: undefined; int232?: undefined; int24?: undefined; int240?: undefined; int248?: undefined; int256?: undefined; int32?: undefined; int40?: undefined; int48?: undefined; int56?: undefined; int64?: undefined; int72?: undefined; int8?: undefined; int80?: undefined; int88?: undefined; int96?: undefined; string?: undefined; uint104?: undefined; uint112?: undefined; uint120?: undefined; uint128?: undefined; uint136?: undefined; uint144?: undefined; uint152?: undefined; uint16?: undefined; uint160?: undefined; uint168?: undefined; uint176?: undefined; uint184?: undefined; uint192?: undefined; uint200?: undefined; uint208?: undefined; uint216?: undefined; uint224?: undefined; uint232?: undefined; uint24?: undefined; uint240?: undefined; uint248?: undefined; uint256?: undefined; uint32?: undefined; uint40?: undefined; uint48?: undefined; uint56?: undefined; uint64?: undefined; uint72?: undefined; uint8?: undefined; uint80?: undefined; uint88?: undefined; uint96?: undefined; } | Record<string, unknown>

TPrimaryType extends string | number | symbol

string

Parameters

ParameterTypeDescription

typedData

TypedDataDefinition<TTypedData, TPrimaryType>

The typed data to be signed

Returns

Promise<`0x${string}`>

A promise that resolves to a hex string representing the signed data