Transfer native tokens and execute IBC transfers using CosmJS with Para wallets
import { useCosmosClient } from "./useCosmosClient";
import { coins } from "@cosmjs/stargate";
function TokenTransfer() {
const { signingClient } = useCosmosClient("https://rpc.cosmos.network");
const sendTokens = async () => {
if (!signingClient) return;
const recipient = "cosmos1..."; // Replace with recipient address
const amount = coins(1000000, "uatom"); // 1 ATOM
const fee = {
amount: coins(5000, "uatom"),
gas: "200000",
};
try {
const accounts = await signingClient.signer.getAccounts();
const sender = accounts[0].address;
const result = await signingClient.sendTokens(
sender,
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);
}
};
return (
<button onClick={sendTokens}>Send 1 ATOM</button>
);
}