import { DirectEthSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { SigningStargateClient, GasPrice, calculateFee } from "@cosmjs/stargate";
const mnemonic =
"copper push brief egg scan entry inform record adjust fossil boss egg " +
"comic alien upon aspect dry avoid interest fury window hint race symptom";
const wallet = await DirectEthSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: "cosmos",
});
const [{ address }] = await wallet.getAccounts();
const client = await SigningStargateClient.connectWithSigner(
"http://localhost:26661",
wallet,
{ gasPrice: GasPrice.fromString("0.025atest") },
);
const recipient = "cosmos1recipient...";
const amount = [{ denom: "atest", amount: "1000000000000000000" }];
// EVM wallets need explicit fees — gas simulation uses the wrong pubkey type.
const fee = calculateFee(200_000, GasPrice.fromString("0.025atest"));
const result = await client.sendTokens(address, recipient, amount, fee);
console.info("Transaction hash:", result.transactionHash);
client.disconnect();
Cosmos EVM
Full Example
End-to-end example of using CosmJS with an EVM-compatible Cosmos chain.
This end-to-end example creates an EVM-compatible wallet, connects to a Cosmos EVM chain, and sends a token transfer using CosmJS.