-
Notifications
You must be signed in to change notification settings - Fork 2
/
WagmiEvents.tsx
51 lines (44 loc) · 1.27 KB
/
WagmiEvents.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { WagmiMintExample } from '../../contracts/WagmiMintExample.sol'
import { useState } from 'react'
import { mainnet, useAccount, useBlockNumber, useContractEvent, useNetwork } from 'wagmi'
import { addresses } from '../utils/addresses'
export const WagmiEvents = () => {
const { address } = useAccount()
const { chain = mainnet } = useNetwork()
const chainId = chain.id
const { data: blockNumber } = useBlockNumber()
// TODO add types to EvmtsContract type
const [events, setEvents] = useState<any[]>([])
/**
* ABI of events can be found at events.Foo
* - Don't call fn and it is an object without args
* - Call fn with args and fromBlock etc. and it returns an object with args
*/
const transferEvents = WagmiMintExample.events.Transfer({
fromBlock: blockNumber && blockNumber - BigInt(1_000),
args: {
to: address,
},
})
useContractEvent({
...transferEvents,
address: addresses[WagmiMintExample.name][chainId as 10],
listener: (event) => {
setEvents([...events, event])
},
})
return (
<div>
<div style={{ display: 'flex', flexDirection: 'column-reverse' }}>
{events.map((event, i) => {
return (
<div>
<div>Event {i}</div>
<div>{JSON.stringify(event)}</div>
</div>
)
})}
</div>
</div>
)
}