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
  • Using the SDK
  • Initialization
  • Connecting your wallet
  • Token transfer
  • Signing Messages
  • Creating accounts
  • Deleting accounts
  • Hacking
  • Resources
  1. SDK
  2. Cross Chain

NEAR

PreviousMultiversX (EGLD)NextIBC

Last updated 3 months ago

NEAR is a user-friendly, scalable layer-1 blockchain platform that uses a sharded proof-of-stake consensus mechanism. It features human-readable account names, supports smart contracts in Rust and AssemblyScript, and offers low transaction fees.

Core Concepts

Setting up your wallet

Use the to create a Near account. Then go to Settings > Security and Recovery > Export Private Key to copy your private key.

Use the to airdrop fund your testnet wallet.

Using the SDK

Initialization

Import the SDK and create a new instance:

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

const rpc_url = "https://rpc.testnet.near.org"
const networkId = "testnet"

const instance = await NEAR.create(rpc_url, networkId)

You can then use the instance to do a read operation on near.

const balance = await instance.getBalance("cwilvx.testnet")
console.log(`Balance: ${balance}Ⓝ`)

Connecting your wallet

To perform token transfers or other transactions, you need to connect your wallet to the SDK. You also need to provide the accountId to be associated with your private key.

await instance.connectWallet(
    "ed25519:4QRNiJk7A584sU3aV1xhqdbdairYJybjHJq9z78s7ntw2JVeBYybZ4r4Ec",
    {
        accountId: "cwilvx.testnet",
    },
)

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

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

Token transfer

To create a transaction to transfer Ⓝ on near, you can use the preparePay or prepareTranfer methods:

const signedTx = await instance.preparePay("cwilvx.testnet", "1.5")

The signed tx is a Uint8Array that can be used in a XM work step.

Signing Messages

const message = "Hello, world!"

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

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

expect(verified).toBe(true)

Creating accounts

You can call the createAccount method to create an account, passing the accountId and the Ⓝ amount to deposit to the created account. You can optionally specify the curve to use when generating the key pair for the new account.

const { keyPair, signedTx } = await instance.createAccount(
    "other.me.testnet",
    "1",
)

console.log(keyPair.getPublicKey().toString())

The method returns the signed transaction for creating the new account on Near, and its key pair.

Deleting accounts

You can delete the connected account by calling the deleteAccount method and passing the NEAR account that will receive the remaining Ⓝ balance from the account being deleted.

const signedTx = await instance.deleteAccount("cwilvx.testnet")

Hacking

To create custom transactions for the Near blockchain using the Demos Near SDK, you can access the underlying API to create transactions.

Method
Description

instance.actions

Transaction Actions

instance.provider

instance.wallet

instance.signer

instance.signTransaction(s)

Sign transactions

Resources

Here's the converted list with markdown links:

The provided by near-api-js

Your connected

The for your connected

Account IDs
Access Keys
Anatomy of a Transaction
Lifecycle of a Transaction
Meteor Wallet
Near Testnet Faucet
Near Website
Near Testnet Faucet
Docs
Meteor Wallet
Near JS API Ref
Near JS Cookbook
Block Explorer
The NEAR Protocol Specification
near class instance
KeyPair
signer
KeyPair