Skip to main content

JavaScript & TypeScript SDK

This reference covers setting up the three major JavaScript/TypeScript frameworks for Monolythium development: CosmJS (Cosmos SDK transactions), viem (EVM interactions), and ethers.js (EVM interactions).


CosmJS

CosmJS is the standard library for Cosmos SDK interactions. Monolythium uses EthSecp256k1 keys and custom message types for MsgBurn and MsgRegisterValidator.

Installation

npm install @cosmjs/stargate @cosmjs/proto-signing @cosmjs/encoding @cosmjs/amino

Client Setup

import { SigningStargateClient, GasPrice } from "@cosmjs/stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { Registry } from "@cosmjs/proto-signing";

// Custom amino types for Monolythium-specific messages
const monoAminoTypes = {
"/monolythium.burn.v1.MsgBurn": {
aminoType: "monolythium/MsgBurn",
toAmino: ({ sender, amount }: { sender: string; amount: { denom: string; amount: string } }) => ({
sender,
amount,
}),
fromAmino: ({ sender, amount }: { sender: string; amount: { denom: string; amount: string } }) => ({
sender,
amount,
}),
},
"/monolythium.validator.v1.MsgRegisterValidator": {
aminoType: "monolythium/MsgRegisterValidator",
toAmino: (msg: any) => msg,
fromAmino: (msg: any) => msg,
},
};

// Connect to testnet
const rpcEndpoint = "https://rpc.testnet.mononodes.xyz";
const gasPrice = GasPrice.fromString("10000000alyth");

const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
"your mnemonic phrase here",
{ prefix: "mono" }
);

const client = await SigningStargateClient.connectWithSigner(
rpcEndpoint,
wallet,
{ gasPrice }
);

const [account] = await wallet.getAccounts();
console.log("Address:", account.address); // mono1...

Query Balance

const balance = await client.getBalance(account.address, "alyth");
const lyth = Number(balance.amount) / 1e18;
console.log(`Balance: ${lyth} LYTH`);

Send Tokens

const result = await client.sendTokens(
account.address,
"mono1recipient...",
[{ denom: "alyth", amount: "1000000000000000000" }], // 1 LYTH
"auto"
);
console.log("Tx hash:", result.transactionHash);

Delegate to Validator

const result = await client.delegateTokens(
account.address,
"monovaloper1validator...",
{ denom: "alyth", amount: "100000000000000000000" }, // 100 LYTH
"auto"
);
console.log("Delegation tx:", result.transactionHash);

Vote on Proposal

import { MsgVote } from "cosmjs-types/cosmos/gov/v1beta1/tx";
import { VoteOption } from "cosmjs-types/cosmos/gov/v1beta1/gov";

const voteMsg = {
typeUrl: "/cosmos.gov.v1beta1.MsgVote",
value: MsgVote.fromPartial({
proposalId: BigInt(1),
voter: account.address,
option: VoteOption.VOTE_OPTION_YES,
}),
};

const result = await client.signAndBroadcast(
account.address,
[voteMsg],
"auto"
);

viem

viem is a lightweight, type-safe EVM library. Define a custom chain for Monolythium and use standard viem APIs.

Installation

npm install viem

Chain Definition

import { defineChain } from "viem";

export const monolythiumTestnet = defineChain({
id: 6940,
name: "Monolythium Testnet",
nativeCurrency: {
decimals: 18,
name: "LYTH",
symbol: "LYTH",
},
rpcUrls: {
default: {
http: ["https://evm.testnet.mononodes.xyz"],
webSocket: ["wss://evm.testnet.mononodes.xyz"],
},
},
blockExplorers: {
default: {
name: "Monoscan",
url: "https://testnet.monoscan.xyz",
},
},
});

export const monolythiumMainnet = defineChain({
id: 6941,
name: "Monolythium",
nativeCurrency: {
decimals: 18,
name: "LYTH",
symbol: "LYTH",
},
rpcUrls: {
default: {
http: ["https://evm.mainnet.mononodes.xyz"],
webSocket: ["wss://evm.mainnet.mononodes.xyz"],
},
},
blockExplorers: {
default: {
name: "Monoscan",
url: "https://monoscan.xyz",
},
},
});

Public Client (Read Operations)

import { createPublicClient, http, formatEther } from "viem";

const client = createPublicClient({
chain: monolythiumTestnet,
transport: http(),
});

// Query balance
const balance = await client.getBalance({
address: "0x1234567890abcdef1234567890abcdef12345678",
});
console.log(`Balance: ${formatEther(balance)} LYTH`);

// Get block number
const blockNumber = await client.getBlockNumber();
console.log("Block:", blockNumber);

// Read contract
const result = await client.readContract({
address: "0xContractAddress...",
abi: contractAbi,
functionName: "balanceOf",
args: ["0xOwnerAddress..."],
});

Wallet Client (Write Operations)

import { createWalletClient, http, parseEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount("0xYourPrivateKey...");

const walletClient = createWalletClient({
account,
chain: monolythiumTestnet,
transport: http(),
});

// Send LYTH
const hash = await walletClient.sendTransaction({
to: "0xRecipient...",
value: parseEther("1.0"),
});
console.log("Tx hash:", hash);
Chain Registry

Instead of defining chains manually, use the @monolythium/chain-registry package which provides pre-configured chain definitions. See Chain Registry.


ethers.js

ethers.js is the most widely used EVM library. Monolythium works with ethers v6 out of the box.

Installation

npm install ethers

Provider Setup

import { ethers } from "ethers";

// HTTP provider (read-only)
const provider = new ethers.JsonRpcProvider(
"https://evm.testnet.mononodes.xyz",
{ chainId: 6940, name: "monolythium-testnet" }
);

// WebSocket provider (subscriptions)
const wsProvider = new ethers.WebSocketProvider(
"wss://evm.testnet.mononodes.xyz"
);

Query Balance

const balance = await provider.getBalance("0xAddress...");
console.log(`Balance: ${ethers.formatEther(balance)} LYTH`);

Send Transaction

const wallet = new ethers.Wallet("0xPrivateKey...", provider);

const tx = await wallet.sendTransaction({
to: "0xRecipient...",
value: ethers.parseEther("1.0"),
});

const receipt = await tx.wait();
console.log("Confirmed in block:", receipt.blockNumber);

Contract Interaction

const contract = new ethers.Contract(
"0xContractAddress...",
contractAbi,
wallet // use provider for read-only
);

// Read
const totalSupply = await contract.totalSupply();

// Write
const tx = await contract.transfer("0xRecipient...", ethers.parseEther("10"));
await tx.wait();

Network Configuration Reference

ParameterTestnetMainnet
Chain ID (EVM)69406941
Chain ID (Cosmos)mono_6940-1mono_6941-1
EVM RPChttps://evm.testnet.mononodes.xyzhttps://evm.mainnet.mononodes.xyz
EVM WebSocketwss://evm.testnet.mononodes.xyzwss://evm.mainnet.mononodes.xyz
Cosmos RPChttps://rpc.testnet.mononodes.xyzhttps://rpc.mainnet.mononodes.xyz
REST APIhttps://api.testnet.mononodes.xyzhttps://api.mainnet.mononodes.xyz
gRPCgrpc.testnet.mononodes.xyz:9090grpc.mainnet.mononodes.xyz:9090
Native denomalyth (18 decimals)alyth (18 decimals)
Bech32 prefixmonomono
Coin type6060