useWatchContractEvent
Primitive that watches and returns emitted contract event logs.
Import
import { useWatchContractEvent } from '@wagmi/solid'Usage
import { useWatchContractEvent } from '@wagmi/solid'
import { abi } from './abi'
function App() {
useWatchContractEvent(() => ({
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
abi,
eventName: 'Transfer',
onLogs(logs) {
console.log('New logs!', logs)
},
}))
}import { createConfig, http } from '@wagmi/solid'
import { mainnet, sepolia } from '@wagmi/solid/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})Parameters
import { useWatchContractEvent } from '@wagmi/solid'
useWatchContractEvent.Parameters
useWatchContractEvent.SolidParametersParameters are passed as a getter function to maintain Solid reactivity.
useWatchContractEvent(() => ({
address: '0x...',
abi,
eventName: 'Transfer',
onLogs(logs) { ... },
}))abi
Abi
The contract's ABI. Check out the TypeScript docs for how to set up ABIs for maximum type inference and safety.
address
Address | undefined
The contract's address.
args
object | readonly unknown[] | undefined
batch
boolean | undefined
- Whether or not the events should be batched on each invocation.
- Defaults to
true.
chainId
config['chains'][number]['id'] | undefined
ID of chain to use when fetching data.
config
Config | undefined
Config to use instead of retrieving from the nearest WagmiProvider.
enabled
boolean | undefined
- Whether or not to watch for events.
- Defaults to
true.
eventName
string
- Event to listen for the contract.
- Inferred from
abi.
onError
((error: Error) => void) | undefined
Error thrown from getting the block number.
onLogs
(logs: Log[], prevLogs: Log[] | undefined) => void
Callback for when logs changes.
poll
boolean | undefined
- Whether or not to use a polling mechanism to check for new blocks instead of a WebSocket subscription.
- Defaults to
falsefor WebSocket Clients, andtruefor non-WebSocket Clients.
pollingInterval
number | undefined
- Polling frequency (in milliseconds).
- Defaults to the Config's
pollingIntervalconfig.
strict
boolean | undefined
- Defaults to
false.
syncConnectedChain
boolean | undefined
- Set up subscriber for connected chain changes.
- Defaults to
Config['syncConnectedChain'].
Return Type
import { useWatchContractEvent } from '@wagmi/solid'
useWatchContractEvent.ReturnTypePrimitive returns void.
Type Inference
With abi setup correctly, TypeScript will infer the correct types for eventName, args, and onLogs parameters. See the Wagmi TypeScript docs for more information.