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
  • Cleaning up
  • Hacking
  • API Reference
  1. SDK
  2. Cross Chain

MultiversX (EGLD)

MultiversX (formerly Elrond) is a highly scalable, fast, and secure blockchain platform for distributed apps, enterprise use cases, and the new internet economy.

Creating the SDK instance

To interact with the MultiversX blockchain, you first need to create an instance of the SDK. Here's how you can do it:

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

const rpc_url = "https://testnet-api.multiversx.com"

const instance = await MULTIVERSX.create(rpc_url)

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

Connecting your wallet

You can connect your wallet using a private key (keyFile) and password as shown below:

const keyFile = '{"version":4,...}' // Your keyFile JSON string
const password = "your-wallet-password"

await instance.connectWallet(keyFile, {
    password: password,
})

Note: In a web environment, if you don't provide a keyFile and password, the SDK will attempt to connect using the MultiversX DeFi Wallet browser extension.

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 recipientAddress = "erd1..."
const amount = "0.00001" // in EGLD

const tx = await instance.preparePay(recipientAddress, amount)

The preparePay method returns a signed transaction ready to be sent to a DEMOS node.

Preparing multiple transactions

You can prepare multiple transactions using the preparePays method:

const transfers = [
    { address: "erd1...", amount: "0.00001" },
    { address: "erd1...", amount: "0.00002" },
]

const txs = await instance.preparePays(transfers)

The preparePays method returns an array of signed transactions. These transactions are signed with increasing nonces derived from the account's current nonce on the network.

Signing messages

const message = "Hello, world!"

// Signing
const signature = await instance.signMessage(message)

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

expect(verified).toBe(true)

Cleaning up

When you're done with the SDK instance, you can disconnect your wallet:

await instance.disconnect()

Hacking

The DEMOS MultiversX SDK provides a limited set of methods to interact with the blockchain. For more advanced usage, you can access the underlying objects:

Property
Type
Description

instance.provider

Provides access to network data

instance.wallet

Manages wallet operations

Example

To get all the tokens owned by an address (a feature not directly implemented in the SDK):

const address = instance.getAddress()
const tokens = await instance.provider.getAllEsdtTokens(new Address(address))

tokens.forEach(token => {
    console.log(`Token: ${token.identifier}, Balance: ${token.balance}`)
})

This example uses the getAllEsdtTokens method from the underlying INetworkProvider, which is not directly exposed in the DEMOS SDK.

For more advanced operations, refer to the following documentation:

API Reference

PreviousSolanaNextNEAR

Last updated 3 months ago

or

MultiversX SDK Core
MultiversX SDK Network Providers
MultiversX SDK Wallet
https://kynesyslabs.github.io/demosdk-api-ref/classes/xmwebsdk.MULTIVERSX.html
INetworkProvider
UserSigner
ExtensionProvider