Skip to main content

Interact with RPC endpoints

As shown on the RPC specifications, there are different endpoints to communicate with the Osmosis chain. Unlike the LCD rest api, the RPC endpoints provide genereic endpoints to communicate with the various modules available. For example the ABCI Query allows you the query different data from Osmosis.

For more information please read generating, [signing and boradcasting transactions.] https://docs.cosmos.network/v0.46/run-node/txs.html on the cosmos-sdk docs.

Querying the ABCI Query with Javascript via Telescope

If you are looking to query, sign and broadcast transactions using Javascript. Telescope and OsmoJS make this very easy. The following is a very simple example of you could acomplish this using Telescope.

Setting up Telescope

# Install dependencies
yarn install
# Install Telescope
npm install -g @osmonauts/telescope
# Select the chains you would like to interact with
telescope install
# Generate types
yarn codegen

Simple query example

Edit src/index.ts


import { osmosis } from "./codegen";
const { createRPCQueryClient } = osmosis.ClientFactory;


async function getBalance() {

const client = await createRPCQueryClient({ rpcEndpoint: "https://rpc.osmosis.zone" });
// // now you can query the cosmos modules
const balance = await client.cosmos.bank.v1beta1
.allBalances({ address: 'osmo1fl48vsnmsdzcv85q5d2q4z5ajdha8yu3aq6l09' });
}

async function getPools() {

const client = await createRPCQueryClient({ rpcEndpoint: "https://rpc.osmosis.zone" });
const pools = await client.osmosis.gamm.v1beta1.pools();
console.log(pools);
}

getPools().catch(console.error);
getBalance().catch(console.error);

Run the code and see the responses from the rpc endpoint.

yarn dev

For extended details and documentations, see the documentation for Telescope.