forked from reown-com/appkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUseContractRead.tsx
44 lines (40 loc) · 1.19 KB
/
UseContractRead.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
import { chains } from '@web3modal/ethereum'
import { useContractRead } from '@web3modal/react'
import wagmigotchiAbi from '../data/wagmigotchiAbi.json'
export default function UseContractRead() {
const config = {
addressOrName: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
contractInterface: wagmigotchiAbi,
functionName: 'getHunger',
chainId: chains.mainnet.id
}
const { data, error, isLoading, refetch } = useContractRead(config)
return (
<section>
<h1>useContractRead</h1>
<p>
This example uses
<a
href="https://etherscan.io/address/0xecb504d39723b0be0e3a9aa33d646642d1051ee1#code"
target="_blank"
rel="noopener noreferer"
>
WagmiGotchi Contract
</a>
on Ethereum
</p>
<ul>
<li>
Contract read config: <span>{JSON.stringify(config)}</span>
</li>
<li>
Returned data: <span>{isLoading ? 'Loading...' : JSON.stringify(data)}</span>
</li>
<li>
Error: <span>{error ? error.message : 'No Error'}</span>
</li>
</ul>
<button onClick={async () => refetch()}>Refetch data</button>
</section>
)
}