The Sunrise client libraries let you query the chain, submit blobs and sign / broadcast transactions from your application without having to run custom protobuf tooling or handβcraft Tendermint JSONβRPC calls.
Available SDKs
JavaScript / TypeScript - Primary SDK available on npm
Rust - gRPC + protobuf type generation with Buf/Prost
Go and Python bindings - Coming soon (contributions welcome)
import {
createEncodeObject,
sunriseTypesRegistry,
} from "@sunriselayer/client";
// The schemas and types for all modules are exported from the client.
// Here, we import the schema for the `MsgCreatePosition` message.
import { MsgCreatePositionSchema } from "@sunriselayer/client/types/liquiditypool";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { SigningStargateClient, coin } from "@cosmjs/stargate";
const RPC = "https://goldberg-rpc.sunrise.node"; // Replace with your node
const SENDER_MNEMONIC = process.env.MNEMONIC!; // Never commit private keys
// This is a simplified example. In a real application, you would fetch pool details
// from a query client and calculate ticks from user-provided prices.
const MOCK_POOL_ID = 1n; // NOTE: Use BigInt for uint64 fields
const MOCK_LOWER_TICK = -20000n;
const MOCK_UPPER_TICK = 20000n;
async function main() {
// 1. Create a wallet and a signer from a mnemonic
const signer = await DirectSecp256k1HdWallet.fromMnemonic(SENDER_MNEMONIC, {
prefix: "sunrise", // The Bech32 address prefix for Sunrise
});
const [account] = await signer.getAccounts();
const senderAddress = account.address;
console.log("Sender address:", senderAddress);
// 2. Create a signing client with the signer and type registry
const client = await SigningStargateClient.connectWithSigner(RPC, signer, {
registry: sunriseTypesRegistry, // The custom type registry for Sunrise messages
});
console.log("Successfully connected to", RPC);
// 3. Prepare a 'Create Position' transaction message
// All message fields are fully typed and validated.
const msg = createEncodeObject(MsgCreatePositionSchema, {
sender: senderAddress,
poolId: MOCK_POOL_ID,
lowerTick: MOCK_LOWER_TICK,
upperTick: MOCK_UPPER_TICK,
// Use the `coin` helper from @cosmjs/stargate to create Coin objects
tokenBase: coin("1000000", "urise"), // 1 RISE
tokenQuote: coin("5000000", "uusdc"), // 5 USDC (example)
minAmountBase: "0", // Slippage protection
minAmountQuote: "0", // Slippage protection
});
// 4. Define the fee and sign and broadcast the transaction
const fee = {
amount: [coin("10000", "uusdrise")],
gas: "400000", // Gas limit
};
const memo = "Created position via @sunriselayer/client";
console.log("Broadcasting transaction...");
const { transactionHash } = await client.signAndBroadcast(
senderAddress,
[msg],
fee,
memo
);
console.log("Successfully created position!");
console.log("Transaction hash:", transactionHash);
}
main().catch(console.error);