Skip to content

Commit 7807c6c

Browse files
author
ignaciosantise
committed
chore: added gas estimation to example
1 parent f0fe98e commit 7807c6c

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

apps/native/App.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
zora,
2929
base,
3030
celo,
31-
aurora
31+
aurora,
32+
sepolia
3233
} from '@wagmi/core/chains';
3334
import { AccountView } from './src/views/AccountView';
3435
import { ActionsView } from './src/views/ActionsView';
@@ -48,7 +49,8 @@ const chains: CreateConfigParameters['chains'] = [
4849
zora,
4950
base,
5051
celo,
51-
aurora
52+
aurora,
53+
sepolia
5254
];
5355

5456
const metadata = {

apps/native/src/views/ActionsView.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { Button, Text } from '@web3modal/ui-react-native';
22
import { View } from 'react-native';
3-
import { useSignMessage, useAccount, useSendTransaction } from 'wagmi';
4-
import { parseEther } from 'viem';
3+
import { useSignMessage, useAccount, useSendTransaction, useEstimateGas } from 'wagmi';
4+
import { Hex, parseEther } from 'viem';
55

66
export function ActionsView() {
77
const { isConnected } = useAccount();
88
const { data, isError, isPending, isSuccess, signMessage } = useSignMessage();
9+
const TX = {
10+
to: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' as Hex, // vitalik.eth
11+
value: parseEther('0.001'),
12+
data: '0x' as Hex
13+
};
14+
const { data: gas, isError: isGasError } = useEstimateGas(TX);
915

1016
const {
1117
data: sendData,
@@ -21,17 +27,9 @@ export function ActionsView() {
2127
Sign
2228
</Button>
2329
{isSuccess && <Text>Signature: {data}</Text>}
30+
{isGasError && <Text>Error estimating gas</Text>}
2431
{isError && <Text>Error signing message</Text>}
25-
<Button
26-
disabled={isSending}
27-
onPress={() =>
28-
sendTransaction({
29-
to: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', // vitalik.eth
30-
value: parseEther('0.001'),
31-
data: '0x'
32-
})
33-
}
34-
>
32+
<Button disabled={isSending} onPress={() => sendTransaction({ ...TX, gas })}>
3533
Send
3634
</Button>
3735
{isSending && <Text>Check Wallet</Text>}

0 commit comments

Comments
 (0)