4.7 KiB
4.7 KiB
blockExplorer
Plugin for fetching ABIs from block explorers that supports the ?module=contract&action=getabi API format.
Import
import { blockExplorer } from '@wagmi/cli/plugins'
Usage
import { defineConfig } from '@wagmi/cli'
import { blockExplorer } from '@wagmi/cli/plugins'
export default defineConfig({
plugins: [
blockExplorer({
baseUrl: 'https://api.etherscan.io/v2/api',
contracts: [
{
name: 'Wagmigotchi',
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
},
],
}),
],
})
Configuration
import { type BlockExplorerConfig } from '@wagmi/cli/plugins'
apiKey
string | undefined
API key for block explorer. Appended to the request URL as query param &apikey=${apiKey}.
import { defineConfig } from '@wagmi/cli'
import { blockExplorer } from '@wagmi/cli/plugins'
export default defineConfig({
plugins: [
blockExplorer({
apiKey: process.env.ETHERSCAN_API_KEY, // [!code focus]
baseUrl: 'https://api.etherscan.io/v2/api',
contracts: [
{
name: 'Wagmigotchi',
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
},
],
}),
],
})
baseUrl
string
Base URL for block explorer.
import { defineConfig } from '@wagmi/cli'
import { blockExplorer } from '@wagmi/cli/plugins'
export default defineConfig({
plugins: [
blockExplorer({
baseUrl: 'https://api.etherscan.io/v2/api', // [!code focus]
contracts: [
{
name: 'Wagmigotchi',
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
},
],
}),
],
})
cacheDuration
number | undefined
Duration in milliseconds to cache ABIs. Defaults to 1_800_000 (30 minutes).
import { defineConfig } from '@wagmi/cli'
import { blockExplorer } from '@wagmi/cli/plugins'
export default defineConfig({
plugins: [
blockExplorer({
baseUrl: 'https://api.etherscan.io/v2/api',
cacheDuration: 300_000, // [!code focus]
contracts: [
{
name: 'Wagmigotchi',
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
},
],
}),
],
})
chainId
number | undefined
Chain ID for block explorer. Appended to the request URL as query param &chainId=${chainId}.
import { defineConfig } from '@wagmi/cli'
import { blockExplorer } from '@wagmi/cli/plugins'
export default defineConfig({
plugins: [
blockExplorer({
apiKey: process.env.ETHERSCAN_API_KEY,
baseUrl: 'https://api.etherscan.io/v2/api',
chainId: 1, // [!code focus]
contracts: [
{
name: 'Wagmigotchi',
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
},
],
}),
],
})
contracts
{ name: string; address?: Address | Record<number, Address> | undefined }[]
Contracts to fetch ABIs for.
import { defineConfig } from '@wagmi/cli'
import { blockExplorer } from '@wagmi/cli/plugins'
export default defineConfig({
plugins: [
blockExplorer({
baseUrl: 'https://api.etherscan.io/v2/api',
contracts: [ // [!code focus]
{ // [!code focus]
name: 'Wagmigotchi', // [!code focus]
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1', // [!code focus]
}, // [!code focus]
], // [!code focus]
}),
],
})
getAddress
((config: { address: Address | Record<number, Address> }) => Address) | undefined
- Function to get address from contract config.
- Defaults to
({ address }) => typeof address === 'string' ? address : Object.values(address)[0].
import { defineConfig } from '@wagmi/cli'
import { blockExplorer } from '@wagmi/cli/plugins'
export default defineConfig({
plugins: [
blockExplorer({
baseUrl: 'https://api.etherscan.io/v2/api',
contracts: [
{
name: 'Wagmigotchi',
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
},
],
getAddress({ address }) { // [!code focus]
if (typeof address === 'string') return address // [!code focus]
return Object.values(address)[0] // [!code focus]
}, // [!code focus]
}),
],
})
name
string
- Name of source.
- Defaults to
'Block Explorer'.
import { defineConfig } from '@wagmi/cli'
import { blockExplorer } from '@wagmi/cli/plugins'
export default defineConfig({
plugins: [
blockExplorer({
baseUrl: 'https://api.etherscan.io/v2/api',
contracts: [
{
name: 'Wagmigotchi',
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
},
],
name: 'Etherscan', // [!code focus]
}),
],
})