This guide demonstrates how to use Para with CosmJS for Cosmos blockchain integration. You’ll learn how to set up the
integration, perform basic operations, and handle transactions using the @getpara/cosmjs-v0-integration
package.
Prerequisites
To use Para, you need an API key. This key authenticates your requests to Para services and is essential for integration. Before integrating Para with your application, ensure you have:
- Completed Para authentication setup in your application (see one of our Setup Guides)
- A valid Para API key
- An RPC endpoint for your desired network
Need an API key? Visit the Developer Portal to create API keys, manage billing, teams, and more.
Installation
Install the required packages using your preferred package manager:
npm install @getpara/cosmjs-v0-integration @cosmjs/stargate
Setup
For basic setup pass your Para instance and the address prefix to the ParaProtoSigner
. Once created pass the signer to
the SigningStargateClient
.
You can also setup a ParaAminoSigner
if you want to use Amino signing instead of Proto signing. The usage is similar, just replace ParaProtoSigner
with ParaAminoSigner
.
import { ParaProtoSigner, createTestTransaction } from "@getpara/cosmjs-v0-integration";
import { SigningStargateClient } from "@cosmjs/stargate";
// Create the Para Proto Signer
// 'prefix' is optional and used for non-cosmos addresses (e.g., 'celestia' for celestia1... addresses)
const signer = new ParaProtoSigner(para, "cosmos");
// Connect to the Cosmos network
const rpcUrl = "https://rpc.cosmos.network"; // Replace with your preferred RPC endpoint
const client = await SigningStargateClient.connectWithSigner(rpcUrl, signer);
// The test transaction sends 0.01 testnet ATOM to your own wallet
const signDoc = await createTestTransaction(para);
const { signature } = await protoSigner.signAmino(signDoc);
Once setup you can using the SigningStargateClient
as you would normally with CosmJS. You can reference the CosmJS Github for more details.
Basic Usage
Get Address and Balance
// Get the signer's address
const address = protoSigner.address;
console.log("Signer address:", address);
// Query account balances
const balance = await client.getAllBalances(address);
console.log("Balance:", balance);
Send Tokens
For sending a transaction you can construct a transaction object and call the sendTokens
method:
const recipient = "cosmos1..."; // Replace with actual recipient address
const amount = {
denom: "uatom",
amount: "1000000", // 1 ATOM
};
const fee = {
amount: [{ denom: "uatom", amount: "500" }],
gas: "200000",
};
try {
const result = await client.sendTokens(protoSigner.address, recipient, [amount], fee);
console.log("Transaction hash:", result.transactionHash);
} catch (error) {
console.error("Error sending transaction:", error);
}
Advanced Transaction Signing
Sometimes you want more control over the transaction and not send the transaction directly. You can construct any valid
message and sign it manually before broadcasting:
import { StdFee, Coin, MsgSendEncodeObject } from "@cosmjs/stargate";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
// Prepare transaction details
const amount: Coin = {
denom: "uatom",
amount: "1000000",
};
const fee: StdFee = {
amount: [{ denom: "uatom", amount: "500" }],
gas: "200000",
};
// Create the message
const message: MsgSend = {
fromAddress: protoSigner.address,
toAddress: "cosmos1...", // recipient address
amount: [amount],
};
const sendMessage: MsgSendEncodeObject = {
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: message,
};
// Sign the transaction
const memo = "Signed with Para";
const signedTx = await client.sign(protoSigner.address, [sendMessage], fee, memo);
// Broadcast the transaction
const result = await client.broadcastTx(signedTx);
console.log("Transaction result:", result);
Multi-Chain Support
To use Para with different Cosmos-based chains, specify the appropriate address prefix and RPC endpoint when creating signers and clients:
// For Osmosis
const osmosisRPC = "https://osmosis-rpc.polkachu.com";
const osmosisSigner = new ParaProtoSigner(para, "osmo");
const osmosisClient = await SigningStargateClient.connectWithSigner(osmosisRPC, osmosisSigner);
Each client will be configured with the appropriate signer for its respective chain, allowing you to interact with multiple Cosmos networks in the same application.
Server-Side Signing
Para’s signers can also be used on the server-side using pregen wallets or an active client side session. To learn more about using para on the server, check out these guides:
Examples
If you’d like to learn more about how to use the ParaProtoSigner
or the ParaAminoSigner
for different transaction types, check out this example in our Examples Hub: