Demos Network Specifications
  • Introduction
    • What is Demos Network
    • Demos Network Architecture
  • FAQ
  • Cookbook
    • Project setup
      • Run the project (MacOS)
      • Run the project (Windows)
        • WSL 2 Setup on Windows (10 and 11 only)
        • Issue Troubleshooting
      • Run the project (Ubuntu)
  • SDK
    • Getting Started
    • WebSDK
      • Authentication
        • FIDO2 Passkeys
          • Under the Hood: FIDO2 Passkeys
      • NodeCalls
      • Transactions
        • Creating a transaction
        • Signing a transaction
        • Broadcasting a transaction
      • L2PS SDK
        • The l2ps module
        • Interacting with the L2PS
        • L2PS Messaging System
      • Instant Messaging
        • What is the Instant Messaging Protocol?
        • Architecture Overview
        • Encryption
        • Quickstart
        • Message Types
        • API Reference
        • FAQ
    • Cross Chain
      • General layout of the XM SDKs
      • EVM
      • BTC
      • Solana
      • MultiversX (EGLD)
      • NEAR
      • IBC
      • TON
      • XRPL
      • The XMScript
      • Identities
    • Demoswork
    • Cookbook
      • Demoswork
        • Creating work steps
        • Conditional Operation
        • Base Operation
        • Signing and broadcasting
      • Transactions
        • Crosschain Transaction
        • Native Transactions
      • SWAP
        • Crosschain SWAP
    • Web2
      • Quick Start
      • DAHR API Reference
        • Types
      • Making Requests
      • Identities
        • Twitter
        • GitHub
    • API Reference
    • Bridges
      • Rubic Bridge Test
    • Post Quantum Cryptography
  • Backend
    • Internal Mechanisms
      • Network Time Synchronization
      • Cross Context Identities
    • Global Change Registry
      • GCR Structure
      • How is GCR Synced?
    • Consensus Mechanism
      • Unparalleled Scalability
      • Decentralization in PoR-BFT
      • Enhanced Security
      • Comparative Advantage
      • Addressing Potential Criticisms
      • Conclusion
    • Communications Stack
    • L2PS (Subnet) Framework
      • How are L2PS transactions handled?
    • Miscellaneous
      • Browsing the Postgres DB via psql
    • Bridges
      • Rubic Bridge
    • Developers Testbed
      • Setting up the environment
      • Setting up the repository
      • Installing dependencies
      • Node Configuration
      • Running the node
  • Frontend
    • Demos Providers Discovery Mechanism
Powered by GitBook
On this page
  • Creating the SDK instance
  • Connecting your wallet
  • Getting your address
  • Preparing a transaction
  • Preparing multiple transactions
  • Signing Messages
  • Verifying signature
  • Cleaning up
  • Hacking
  • API Reference
  1. SDK
  2. Cross Chain

IBC

Inter-Blockchain Communication Protocol (IBC) is a blockchain interoperability protocol used by 110+ chains. It enables secure, permissionless, feature-rich cross-chain interactions.

Creating the SDK instance

I'll be using the Stargaze testnet for the examples.

import { IBC } from "@kynesyslabs/demosdk/xm-websdk"

const rpc_url = "https://rpc.elgafar-1.stargaze-apis.com"

const instance = await IBC.create(rpc_url)

The instance is now connected to the Stargaze testnet and ready to be used.

Connecting your wallet

You can connect your wallet using a mnemonic or a private key as shown below.

const mnemonic = "stumble august fancy ..."

await instance.connectWallet(mnemonic, {
    prefix: "stars",
    gasPrice: "0.012ustars",
})

When connecting your wallet, you also need to specify the address prefix for your chain and the gas price to be used when creating transactions.

Getting your address

You can get your address using the getAddress method.

const address = instance.getAddress()

Preparing a transaction

You can prepare a transaction using the preparePay method.

const tx = await instance.preparePay(address, "1", {
    denom: "ustars",
})

When creating a transaction, you need to specify the recipient address, the amount to be transferred, and the token denomination.

Preparing multiple transactions

You can prepare multiple transactions using the preparePays method.

const txs = await instance.preparePays(
    [
        { address: "stars1zyxw...", amount: "1" },
        { address: "stars1abcd...", amount: "1" },
    ],
    {
        denom: "ustars",
    },
)

The preparePays method returns an array of signed transactions ready to be sent to a DEMOS node. The transactions are signed with an incrementing nonce derived from the ledger sequence.

Signing Messages

const message = "Hello, world!"

// Signing
const signature = await instance.signMessage(message, {
    privateKey: "<mnemonic here>",
})

console.log(signature)

Verifying signature


// Get account public key
const sep256k1HdWallet = await DirectSecp256k1HdWallet.fromMnemonic(
    wallets.ibc.privateKey,
    {
        prefix: "stars", // network prefix here
    },
)

const walletAccounts = await sep256k1HdWallet.getAccounts()
const currentAccount = walletAccounts.find(account =>
    account.address.startsWith("stars"),
)

const pubKey = currentAccount?.pubkey
const ibcBase64PublicKey = Buffer.from(pubKey).toString("base64")

// Verifying signature
const verified = await instance.verifyMessage(
    message,
    signature,
    ibcBase64PublicKey,
)

expect(verified).toBe(true)

Cleaning up

When you're done with the SDK instance, you can disconnect your wallet and RPC connection.

await instance.disconnect()

Hacking

You can access the underlying CosmJS objects to have more control over the transactions and interactions with the blockchain.

Here is a list of the objects you can access:

Property
Type
Description

instance.provider

Provides read-only access to blockchain data

instance.wallet

Allows for signing and broadcasting transactions

instance.signer

Manages the private key and signing operations

Example

To get the latest block, you can use the getBlock method.

const block = await instance.provider.getBlock()

API Reference

PreviousNEARNextTON

Last updated 3 months ago

The DEMOS IBC SDK is built on top of the library, and only provides a limited set of methods to interact with the blockchain.

or

CosmJS
https://kynesyslabs.github.io/demosdk-api-ref/classes/xmwebsdk.IBC.html
StargateClient
SigningStargateClient
DirectSecp256k1Wallet
DirectSecp256k1HdWallet