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
  • Core Concepts
  • Setting up your wallet
  • Initialization
  • Connecting your wallet
  • Creating a token transfer payload
  • Creating multiple transfer payload
  • Checking balance
  • Signing messages
  • Working with smart contracts
  • Listening for events (Not implemented)
  • Cleaning up
  • Advanced usage
  • API Reference
  • Resources
  1. SDK
  2. Cross Chain

EVM

PreviousGeneral layout of the XM SDKsNextBTC

Last updated 3 months ago

The Ethereum Virtual Machine (EVM) is the runtime environment for smart contracts in Ethereum. It's a fundamental part of the Ethereum network and is used by many other blockchain platforms that aim to provide Ethereum-like functionality. Our EVM SDK provides a simple interface to interact with EVM-compatible blockchains.

Core Concepts

  1. : Ethereum addresses that can hold balance and send transactions

  2. : Signed data packages that store a message to be sent from an externally owned account

  3. : The fee required to execute operations on the Ethereum network

  4. : Programs that run on the Ethereum blockchain

Setting up your wallet

To interact with EVM-compatible chains, you'll need a wallet with a private key. You can use tools like MetaMask or hardware wallets to generate and manage your keys securely.

For testing purposes, you can use faucets to get testnet tokens. For example, for Sepolia testnet:

Initialization

Import the SDK and create a new instance:

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

const rpc_url = "https://sepolia.infura.io/v3/YOUR-PROJECT-ID"
const instance = await EVM.create(rpc_url)

Connecting your wallet

To create signed transaction payloads, you need to connect your wallet to the SDK:

const privateKey = "0x1234567890abcdef..." // Your private key
await instance.connectWallet(privateKey)

You can view the address of your connected wallet using the getAddress method:

const address = instance.getAddress()
console.log(`Address: ${address}`)

Creating a token transfer payload

To create a signed transaction payload to transfer ETH, you can use the preparePay method:

const recipientAddress = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
const amount = "0.1" // Amount in ETH
const signedTx = await instance.preparePay(recipientAddress, amount)

The signedTx is a signed transaction that can be used a DEMOS transaction.

Creating multiple transfer payload

You can prepare multiple signed transaction payloads at once using the preparePays method:

const transfers = [
    { address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", amount: "0.1" },
    { address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", amount: "0.2" },
]
const signedTxs = await instance.preparePays(transfers)

The signedTxs is an array of signed transaction payloads that can be used in a DEMOS transaction.

Checking balance

You can check the balance of an address using the getBalance method:

const balance = await instance.getBalance(
    "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
)
console.log(`Balance: ${balance} ETH`)

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)

Working with smart contracts

The SDK provides methods to interact with smart contracts:

const contractAddress = "0x..."
const abi = [...] // Contract ABI

const contract = await instance.getContractInstance(contractAddress, abi)

// Read from contract
const result = await instance.readFromContract(contract, "functionName", [arg1, arg2])

// Write to contract
await instance.writeToContract(contract, "functionName", [arg1, arg2])

Listening for events (Not implemented)

You can listen for specific events or all events from a contract:

// Listen for a specific event
instance.listenForEvent("EventName", contractAddress, abi)

// Listen for all events
instance.listenForAllEvents(contractAddress, abi)

Cleaning up

To disconnect your wallet and clean up resources, you can use the disconnect method:

await instance.disconnect()

Advanced usage

For more advanced use cases, you can access underlying properties and methods of the EVM instance:

Property/Method
Description
API Reference

instance.provider

The JsonRpcProvider instance for interacting with the Ethereum network

instance.wallet

The Wallet instance representing the connected account

instance.contracts

A Map of Contract instances for interacting with smart contracts

instance.signTransaction(s)

Method(s) to sign one or multiple transactions

-

You can use these properties and methods to perform custom operations:

const blockNumber = await instance.provider.getBlockNumber()

API Reference

Resources

Accounts
Transactions
Gas
Smart Contracts
Alchemy Sepolia Faucet
Chainlink Sepolia Faucet
https://kynesyslabs.github.io/demosdk-api-ref/classes/xmwebsdk.EVM.html
Ethereum Website
Ethers.js Documentation
MetaMask
Ethereum Block Explorer (Mainnet)
Sepolia Block Explorer
JsonRpcProvider
Wallet
Contract