QubicTypeScript

Getting started

Install the SDK and send your first QU transfer in under 5 minutes.

This guide takes you from zero to a working, signed transaction. You only need two packages to get started.

The SDK is built for Bun. All examples use bun as the runtime. Node.js works too — swap bun for node and use npm/pnpm to install.

Install

bun add @qubic.org/wallet @qubic.org/rpc
npm install @qubic.org/wallet @qubic.org/rpc
pnpm add @qubic.org/wallet @qubic.org/rpc

@qubic.org/wallet handles seed management and transaction signing. @qubic.org/rpc talks to the Qubic RPC gateway.

Steps

Generate a seed

A seed is a 55-character lowercase string that acts as your private key. Keep it secret.

send-transfer.ts
import { generateSeed, createWallet } from "@qubic.org/wallet"

const seed = generateSeed()
const wallet = createWallet(seed)

console.log("Identity:", wallet.identity)
// BZBQFLLBNCXEMGLOBHUVGPQVZEJYLRQTCMQCXCMQTQJAZXQCQXQCQXQCQ

Never hard-code a seed in source code or commit it to git. In production, load it from an environment variable or unlock it from an encrypted vault. See the vault guide for details.

Connect to the network and fetch the current tick

The tick is the Qubic equivalent of a block number. You need it to set a target tick for your transaction.

send-transfer.ts
import { createLiveClient } from "@qubic.org/rpc"

const live = createLiveClient()
// Defaults to https://rpc.qubic.org/live/v1

const { tick, epoch } = await live.getTickInfo()
console.log(`Tick ${tick}, epoch ${epoch}`)

Build and sign a transfer

Set targetTick a few ticks ahead of the current tick. The network rejects transactions whose target tick has already passed.

send-transfer.ts
import { toIdentity } from "@qubic.org/types"

const destination = toIdentity("CFBMEMZOIDEXQAUXYYSZIURADQLAPWPMNJXQSNVQZAHYVOPYUKKJBJUCTVJL")

const { encoded, hash } = await wallet.buildTransfer({
  destination,
  amount: 1_000_000n,    // QU amount as bigint
  targetTick: tick + 5,
  currentTick: tick,
})

encoded is the base64-encoded signed transaction ready for broadcast. hash is the 60-character transaction hash you can use to track the transaction later.

Broadcast

send-transfer.ts
const result = await live.broadcastTransaction(encoded)
console.log(`Broadcast to ${result.peersBroadcastedTo} peers`)
console.log(`TX hash: ${hash}`)

Complete script

send-transfer.ts
import { generateSeed, createWallet } from "@qubic.org/wallet"
import { createLiveClient } from "@qubic.org/rpc"
import { toIdentity } from "@qubic.org/types"

const seed = generateSeed()
const wallet = createWallet(seed)
const live = createLiveClient()

const { tick } = await live.getTickInfo()

const destination = toIdentity("CFBMEMZOIDEXQAUXYYSZIURADQLAPWPMNJXQSNVQZAHYVOPYUKKJBJUCTVJL")

const { encoded, hash } = await wallet.buildTransfer({
  destination,
  amount: 1_000_000n,
  targetTick: tick + 5,
  currentTick: tick,
})

const result = await live.broadcastTransaction(encoded)
console.log(`Peers: ${result.peersBroadcastedTo}`)
console.log(`TX hash: ${hash}`)

Run it:

bun run send-transfer.ts

What's next

On this page