Skip to content

getClient

Action for getting Viem Client instance.

Import

ts
import { getClient } from '@wagmi/core'
import { getClient } from '@wagmi/core'

Usage

ts
import { getClient } from '@wagmi/core'
import { config } from './config'

const client = getClient(config)
import { getClient } from '@wagmi/core'
import { config } from './config'

const client = getClient(config)
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Parameters

ts
import { type GetClientParameters } from '@wagmi/core'
import { type GetClientParameters } from '@wagmi/core'

chainId

config['chains'][number]['id'] | undefined

ID of chain to use when getting Viem Client.

ts
import { getClient } from '@wagmi/core'
import { mainnet } from '@wagmi/core/chains'
import { config } from './config'

const client = await getClient(config, {
  chainId: mainnet.id, 
})
import { getClient } from '@wagmi/core'
import { mainnet } from '@wagmi/core/chains'
import { config } from './config'

const client = await getClient(config, {
  chainId: mainnet.id, 
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Return Type

ts
import { type GetClientReturnType } from '@wagmi/core'
import { type GetClientReturnType } from '@wagmi/core'

Client

Viem Client instance.

Released under the MIT License.