3.9 KiB

title, description
title description
useBytecode Composable for retrieving the bytecode at an address.

useBytecode

Composable for retrieving the bytecode at an address.

Import

import { useBytecode } from '@wagmi/vue'

Usage

::: code-group

<script setup lang="ts">
import { useBytecode } from '@wagmi/vue'

const { data: byteCode } = useBytecode({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
</script>

<template>
  Byte Code: {{ byteCode }}
</template>

<<< @/snippets/react/config.ts[config.ts] :::

Parameters

import { type UseBytecodeParameters } from '@wagmi/vue'

address

Address | undefined

The contract address.

::: code-group

<script setup lang="ts">
import { useBytecode } from '@wagmi/vue'

const { data: byteCode } = useBytecode({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', // [!code focus]
})
</script>

<template>
  Byte Code: {{ byteCode }}
</template>

<<< @/snippets/react/config.ts[config.ts] :::

blockNumber

bigint | undefined

The block number to check the bytecode at.

::: code-group

<script setup lang="ts">
import { useBytecode } from '@wagmi/vue'

const { data: byteCode } = useBytecode({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  blockNumber: 16280770n, // [!code focus]
})
</script>

<template>
  Byte Code: {{ byteCode }}
</template>

<<< @/snippets/react/config.ts[config.ts] :::

blockTag

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

The block tag to check the bytecode at.

::: code-group

<script setup lang="ts">
import { useBytecode } from '@wagmi/vue'

const { data: byteCode } = useBytecode({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  blockTag: 'safe', // [!code focus]
})
</script>

<template>
  Byte Code: {{ byteCode }}
</template>

<<< @/snippets/react/config.ts[config.ts] :::

chainId

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

The chain ID to check the bytecode at.

::: code-group

<script setup lang="ts">
import { useBytecode } from '@wagmi/vue'
import { mainnet } from '@wagmi/vue/chains'

const { data: byteCode } = useBytecode({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  chainId: mainnet.id, // [!code focus]
})
</script>

<template>
  Byte Code: {{ byteCode }}
</template>

<<< @/snippets/react/config.ts[config.ts] :::

config

Config | undefined

Config to use instead of retrieving from the nearest WagmiProvider.

::: code-group

<script setup lang="ts">
import { useBytecode } from '@wagmi/vue'
import { config } from './config' // [!code focus]

const { data: byteCode } = useBytecode({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  config, // [!code focus]
})
</script>

<template>
  Byte Code: {{ byteCode }}
</template>

<<< @/snippets/react/config.ts[config.ts] :::

scopeKey

string | undefined

Scopes the cache to a given context. Hooks that have identical context will share the same cache.

::: code-group

<script setup lang="ts">
import { useBytecode } from '@wagmi/vue'
import { config } from './config' // [!code focus]

const { data: byteCode } = useBytecode({
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  scopeKey: 'foo', // [!code focus]
})
</script>

<template>
  Byte Code: {{ byteCode }}
</template>

<<< @/snippets/react/config.ts[config.ts] :::

Return Type

import { type UseBytecodeReturnType } from '@wagmi/vue'

Action