import {
CosmWasmClient,
SigningCosmWasmClient,
} from "@cosmjs/cosmwasm-stargate";
import { coins, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { GasPrice } from "@cosmjs/stargate";
import { SigningStargateClient } from "@cosmjs/stargate";
const rpc = 'YOUR_RPC_URL_HERE';
const mnemonic = 'YOUR_MNEMONIC_HERE';
const prefix = 'YOUR_CHAIN_PREFIX_HERE';
const start = async () => {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: prefix
});
const [firstAccount] = await wallet.getAccounts();
const walletAddress = firstAccount.address;
console.log('Wallet Address:', walletAddress);
const signingClient = await SigningStargateClient.connectWithSigner(
rpc,
wallet,
{ gasPrice: GasPrice.fromString("0.1YOUR_GAS_TOKEN_HERE") }
);
// Replace with the recipient's address
const recipient = 'RECIPIENT_ADDRESS_HERE';
// Replace with the appropriate token denomination and amount to transfer
const amount = {
denom: "YOUR_TOKEN_DENOMINATION_HERE",
amount: "YOUR_TOKEN_AMOUNT_HERE",
};
// The timeout is set to one hour in the future as an example, adjust as needed
const timeoutTimestamp = Math.floor(Date.now() / 1000) + 60 * 60;
const tx = await signingClient.sendIbcTokens(
walletAddress,
recipient,
amount,
'YOUR_PORT_HERE', // Usually 'transfer', replace if different
'YOUR_CHANNEL_HERE', // Replace with the channel identifier (e.g., 'channel-0')
undefined, // Timeout block height, leave undefined if using timeout timestamp
timeoutTimestamp,
"auto", // Fee, set to "auto" to automatically calculate the fee
"" // Memo, optional
);
console.log(JSON.stringify(tx));
};
start();