Skip to content

getBytecode

Action for retrieving the bytecode at an address.

Import

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

Usage

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

await getBytecode(config, {
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
import { getBytecode } from '@wagmi/core'
import { config } from './config'

await getBytecode(config, {
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
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 GetBytecodeParameters } from '@wagmi/core'
import { type GetBytecodeParameters } from '@wagmi/core'

address

Address

The contract address.

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

await getBytecode(config, {
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', 
})
import { getBytecode } from '@wagmi/core'
import { config } from './config'

await getBytecode(config, {
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', 
})
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(),
  },
})

blockNumber

bigint | undefined

The block number to check the bytecode at.

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

await getBytecode(config, {
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  blockNumber: 16280770n, 
})
import { getBytecode } from '@wagmi/core'
import { config } from './config'

await getBytecode(config, {
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  blockNumber: 16280770n, 
})
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(),
  },
})

blockTag

'latest' | 'earliest' | 'pending' | 'safe' | 'finalized' | undefined

The block tag to check the bytecode at.

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

await getBytecode(config, {
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  blockTag: 'safe', 
})
import { getBytecode } from '@wagmi/core'
import { config } from './config'

await getBytecode(config, {
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  blockTag: 'safe', 
})
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(),
  },
})

chainId

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

The chain ID to check the bytecode at.

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

await getBytecode(config, {
  chainId: mainnet.id, 
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
import { getBytecode } from '@wagmi/core'
import { mainnet } from '@wagmi/core/chains'
import { config } from './config'

await getBytecode(config, {
  chainId: mainnet.id, 
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
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 GetBytecodeReturnType } from '@wagmi/core'
import { type GetBytecodeReturnType } from '@wagmi/core'

Hex

The contract's bytecode.

Error

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

TanStack Query

ts
import {
  type getBytecodeData,
  type getBytecodeOptions,
  type getBytecodeQueryFnData,
  type getBytecodeQueryKey,
  getBytecodeQueryKey,
  getBytecodeQueryOptions,
} from '@wagmi/core/query'
import {
  type getBytecodeData,
  type getBytecodeOptions,
  type getBytecodeQueryFnData,
  type getBytecodeQueryKey,
  getBytecodeQueryKey,
  getBytecodeQueryOptions,
} from '@wagmi/core/query'

Viem

Released under the MIT License.