forked from reown-com/appkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UseSendTransaction.tsx
46 lines (42 loc) · 1.44 KB
/
UseSendTransaction.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
import { chains } from '@web3modal/ethereum'
import { useSendTransaction, useWaitForTransaction } from '@web3modal/react'
import { BigNumber } from 'ethers'
const { id: chainId } = chains.avalancheFuji
export default function UseSendTransaction() {
const transaction = {
request: {
to: '0x000000000000000000000000000000000000dead',
value: BigNumber.from('10000000000000000')
},
chainId
}
const { data, error, isLoading, sendTransaction } = useSendTransaction(transaction)
const { receipt, isWaiting } = useWaitForTransaction({ hash: data?.hash })
return (
<section>
<h1>useSendTransaction / useWaitForTransaction</h1>
<p>
Note: This example uses avalance fuji testnet, you will need some testnet avax from the
faucet
<a href="https://faucet.avax.network/" target="_blank" rel="noopener noreferer">
https://faucet.avax.network/
</a>
</p>
<ul>
<li>
Request: <span>{JSON.stringify(transaction)}</span>
</li>
<li>
Send Data: <span>{isLoading ? 'Loading...' : JSON.stringify(data)}</span>
</li>
<li>
Receipt Data: <span>{isWaiting ? 'Waiting...' : JSON.stringify(receipt)}</span>
</li>
<li>
Error: <span>{error ? error.message : 'No Error'}</span>
</li>
</ul>
<button onClick={async () => sendTransaction()}>Send Transaction</button>
</section>
)
}