Prerequisites
Send Tokens
import { View, Text, Button } from 'react-native';
import { useParaCosmos } from './hooks/useParaCosmos';
import { SigningStargateClient, coins } from '@cosmjs/stargate';
const RPC_URL = 'https://rpc.cosmos.directory/cosmoshub';
function TokenTransfer() {
const { protoSigner, address, isLoading } = useParaCosmos();
const sendTokens = async () => {
if (!protoSigner || !address) return;
const recipient = 'cosmos1...';
const amount = coins(1000000, 'uatom');
const fee = {
amount: coins(5000, 'uatom'),
gas: '200000',
};
try {
const client = await SigningStargateClient.connectWithSigner(RPC_URL, protoSigner);
const result = await client.sendTokens(
address,
recipient,
amount,
fee,
'Sent via Para'
);
console.log('Transaction hash:', result.transactionHash);
console.log('Gas used:', result.gasUsed);
} catch (error) {
console.error('Transfer failed:', error);
}
};
if (isLoading) return <Text>Loading...</Text>;
return (
<View>
<Text>From: {address}</Text>
<Button title="Send 1 ATOM" onPress={sendTokens} />
</View>
);
}