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 an SDK instance
  • Changing the RPC URL
  • Reading Blockchain data
  • Connecting a private key
  • Creating a single transaction
  • Creating multiple transactions
  • Cleaning up
  1. SDK
  2. Cross Chain

General layout of the XM SDKs

All the crosschain SDKs share the same interface, with a few blockchain-specific methods occuring on some SDKS.

To demonstrate the general layout of the SDKs, let's use the EVM crosschain SDK for the web.

Creating an SDK instance

Start by instantiating the SDK class using a RPC url.

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

const rpc_url = "https://rpc.ankr.com/eth_sepolia"
const instance = await EVM.create()

The create method will ping the RPC and return an instance of the SDK connected to the RPC.

Changing the RPC URL

You can assign a new rpc url as shown:

instance.setRpc("<new_rpc_url>")
await instance.connect()

Reading Blockchain data

You can access now acess Blockchain data using the helper methods provided by the SDK. For example, to read an address balance:

const balance = instance.getBalance("0xa5...")

You can access additional methods for reading blockchain data by exploring the provider object inside the SDK instance. For example, to get the latest block on Ethereum:

const block = await instance.provider.getBlock("latest")

The shape of the provider object is SDK specific. Please find the link to the API reference at the bottom of the specific crosschain SDK documentation page.

Connecting a private key

To create and sign payloads, you need to attach your private key to your SDK instance.

const privateKey = "0xaAIf..."
const wallet = await instance.connectWallet(privateKey)

The connectWallet method returns the wallet object that holds your private key inside the SDK instance.

The shape of the wallet object is SDK specific. Please find the link to the API reference at the bottom of the specific crosschain SDK documentation page.

You can now check the public key of your connect wallet.

const publicKey = instance.getAddress()

Creating a single transaction

You can create transaction to send funds to addresses using the provided methods.

const destination = "0x4d..."
const signedTx = await instance.prepareTransfer(destination, "0.1")

The preparePay method creates a transaction to transfer funds to a destination address. It also signs the transaction using the connected private key. It returns the payload ready to be used in a DEMOS transaction.

The prepareTransfer method is an alias of the preparePay method.

Creating multiple transactions

You can also create a list of transaction to transfer funds.

const transfers = [
    {
        address: "0xf0...",
        amount: "0.1",
    },
    {
        address: "0x4f...",
        amount: "0.25",
    },
]

const signedTxs = await instance.prepareTransfers(transfers)

The prepareTransfers method creates and signs a list of transaction to transfer funds in the order of appearance.

Cleaning up

When you no longer need the instance, disconnect the rpc and your wallet.

await instance.disconnect()
PreviousCross ChainNextEVM

Last updated 8 months ago