VIZ.cx

SDK Reference

@viz-cx/core — TypeScript client for the VIZ blockchain.

Installation

npm install @viz-cx/core

Setup

import { createClient } from '@viz-cx/core'

// Read-only client (no key required)
const client = createClient({ endpoint: 'https://node.viz.cx' })

Reading data

All read methods are on client.api (the ReadApi interface). They are async and return null when a resource does not exist.

// Dynamic global properties
const dgp = await client.api.getDynamicGlobalProperties()
console.log(dgp.head_block_number, dgp.current_supply)

// Account(s)
const [alice] = await client.api.getAccounts(['alice'])
console.log(alice.balance, alice.vesting_shares, alice.energy)

// Block
const block = await client.api.getBlock(1)
console.log(block?.timestamp, block?.witness)

// Account history (last 10 ops)
const history = await client.api.getAccountHistory('alice', -1, 10)
for (const [, item] of history) {
  console.log(item.op[0], item.timestamp)
}

Asset formatting

Asset is an immutable value object for VIZ token amounts. Use Asset.parse(str) to parse chain strings like "10.000 VIZ".

import { Asset, viz, shares } from '@viz-cx/core'

const amount = Asset.parse('10.000 VIZ')
console.log(amount.toString()) // "10.000 VIZ"

const v = viz('5.000')    // Asset<'VIZ'>
const s = shares('100.000000') // Asset<'SHARES'>

console.log(v.add(viz('1.000')).toString()) // "6.000 VIZ"

WebSocket subscription

Subscribe to the live op feed at wss://api.viz.cx/ws/ops. Each message is a JSON-encoded operation record with trx_id, timestamp, and op.

const ws = new WebSocket('wss://api.viz.cx/ws/ops')

ws.onmessage = (event) => {
  const item = JSON.parse(event.data)
  const [opType, opData] = item.op
  if (opType === 'award') {
    console.log(`${opData.initiator} awarded ${opData.receiver}`)
  }
}

ws.onclose = () => {
  // Reconnect after 3 seconds
  setTimeout(() => connectFeed(), 3000)
}

Signing & broadcasting

Pass account and activeKey to createClient to get a full client with curated broadcast methods. Never expose WIF keys in client-side (browser) code. Use this pattern in server-side scripts or backend services only.

import { createClient } from '@viz-cx/core'

// Full client with signing (requires account + active key)
const client = createClient({
  account: 'alice',
  activeKey: process.env.VIZ_ACTIVE_KEY!, // WIF string — never expose client-side
  endpoint: 'https://node.viz.cx',
})

// Award another account
const result = await client.award({
  receiver: 'bob',
  energy: 100,  // % of energy to spend (100 = use 100% of current energy)
  memo: 'Great contribution!',
})
console.log('tx id:', result.id)