Skip to main content

Quick Start

This guide will have you connected to the DEMOS Network and querying the blockchain in just a few minutes.
1

Install the SDK

Add the DEMOS SDK to your project using bun (recommended):
bun add @kynesyslabs/demosdk@latest
For browser environments, you’ll need Buffer polyfills. See Getting Started for Vite configuration.
2

Create a Wallet

Generate a new wallet with a mnemonic seed phrase:
import { Demos } from "@kynesyslabs/demosdk/websdk"

const demos = new Demos()

// Generate a new mnemonic (save this securely!)
const mnemonic = demos.newMnemonic()
console.log("Your mnemonic:", mnemonic)

// Connect using the mnemonic
const publicKey = await demos.connectWallet(mnemonic, {
    algorithm: "ed25519",
})
console.log("Your public key:", publicKey)
Security: Never share your mnemonic. Store it securely - it controls access to all your keys.
3

Connect to the Network

Connect to a DEMOS RPC node:
await demos.connect("https://node2.demos.sh")

if (demos.connected) {
    console.log("Connected to DEMOS Network!")
}
4

Query the Blockchain

Now you can read data from the blockchain:
// Get the latest block number
const blockNumber = await demos.getLastBlockNumber()
console.log("Latest block:", blockNumber)

// Get the latest block hash
const blockHash = await demos.getLastBlockHash()
console.log("Latest block hash:", blockHash)

// Get your wallet info
const address = demos.getAddress()
const addressInfo = await demos.getAddressInfo(address)
console.log("Your wallet info:", addressInfo)
5

Sign a Message

Test your wallet by signing and verifying a message:
const message = "Hello DEMOS Network!"

// Sign the message
const signature = await demos.signMessage(message)
console.log("Signature:", signature)

// Verify the signature
const publicKey = demos.getAddress()
const isValid = await demos.verifyMessage(
    message,
    signature.data,
    publicKey,
    { algorithm: signature.type }
)
console.log("Signature valid:", isValid)

Complete Example

Here’s the full code to copy and run:
import { Demos } from "@kynesyslabs/demosdk/websdk"

async function main() {
    // Initialize
    const demos = new Demos()

    // Create wallet
    const mnemonic = demos.newMnemonic()
    console.log("Mnemonic:", mnemonic)

    const publicKey = await demos.connectWallet(mnemonic, {
        algorithm: "ed25519",
    })
    console.log("Public key:", publicKey)

    // Connect to network
    await demos.connect("https://node2.demos.sh")
    console.log("Connected:", demos.connected)

    // Query blockchain
    const blockNumber = await demos.getLastBlockNumber()
    console.log("Latest block:", blockNumber)

    // Sign message
    const signature = await demos.signMessage("Hello DEMOS!")
    console.log("Signed message successfully!")

    // Clean up
    demos.disconnect()
}

main().catch(console.error)

Next Steps