Skip to content

Commit 59ac69e

Browse files
committed
send token successful
1 parent 89c2957 commit 59ac69e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

examples/vite-react/src/App.tsx

+16-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
DENOM_DISPLAY,
3131
DECIMAL,
3232
} from './utils/constants';
33+
import { SigningStargateClient } from '@cosmjs/stargate';
3334

3435
function App() {
3536
const [address, setAddress] = useState('');
@@ -43,6 +44,9 @@ function App() {
4344
reset,
4445
} = useForm<TransferFormData>({
4546
resolver: zodResolver(transferFormSchema),
47+
defaultValues: {
48+
amount: "0.000001",
49+
},
4650
});
4751

4852
const { data: balance, refetch: refetchBalance } = useQuery({
@@ -59,16 +63,16 @@ function App() {
5963
const data = await response.json();
6064
// Log the response to see what we're getting
6165
console.log('Balance response:', data);
62-
66+
6367
if (!data.balances) {
6468
return 0;
6569
}
66-
70+
6771
const atomBalance = data.balances.find((b: any) => b.denom === DENOM);
6872
if (!atomBalance) {
6973
return 0;
7074
}
71-
75+
7276
return Number(atomBalance.amount) / Math.pow(10, DECIMAL);
7377
} catch (error) {
7478
console.error('Error fetching balance:', error);
@@ -101,8 +105,13 @@ function App() {
101105
},
102106
};
103107

104-
const signer = await window.keplr.getOfflineSigner(CHAIN_ID);
105-
const response = await signer.signAndBroadcast(msg);
108+
const offlineSigner = window.keplr.getOfflineSigner(CHAIN_ID);
109+
const client = await SigningStargateClient.connectWithSigner(RPC_ENDPOINT, offlineSigner);
110+
const fee = {
111+
amount: [{ denom: DENOM, amount: "5000" }], // adjust fee amount as needed
112+
gas: "200000" // adjust gas limit as needed
113+
};
114+
const response = await client.signAndBroadcast(address, [msg], fee);
106115
return response.transactionHash;
107116
},
108117
onSuccess: (txHash) => {
@@ -197,7 +206,7 @@ function App() {
197206
<CardBody>
198207
<VStack spacing={4} align="stretch">
199208
<Heading size="md">Cosmos Wallet</Heading>
200-
209+
201210
{!address ? (
202211
<Button onClick={connectWallet}>Connect Keplr</Button>
203212
) : (
@@ -214,7 +223,7 @@ function App() {
214223
onClick={handleRefreshBalance}
215224
/>
216225
</HStack>
217-
226+
218227
<form onSubmit={handleSubmit(onSubmit)}>
219228
<VStack spacing={4}>
220229
<FormControl isInvalid={!!errors.recipient}>

0 commit comments

Comments
 (0)