QubicTypeScript
Packages

@qubic.org/contracts

Generated typed wrappers for every deployed Qubic smart contract. Zero manual payload construction required.

Introduction

Generated, not hand-written

The wrappers in this package are output from a code generator that reads the latest @qubic.org/registry snapshot and produces typed functions for every contract, procedure, and read function. When a new epoch ships a changed ABI, the SDK maintainers run the generator and publish an updated version.

Three things per procedure/function

For each contract operation you get:

  1. Builder — encodes a JS object to binary: buildQearnLockInput({ amount })
  2. Decoder — decodes binary response bytes to a typed object: decodeQearnLockOutput(bytes)
  3. Caller (read functions only) — calls the RPC gateway and returns Result<T, QubicRpcError>: qearnGetStateOfRound(live, input, converters)

Namespace pattern

Every contract is also exported as a namespace object that groups all three:

import { qearn } from "@qubic.org/contracts"

qearn.contractIndex          // 9
qearn.buildLockInput(...)    // payload builder
qearn.decodeLockOutput(...)  // output decoder
qearn.getStateOfRound(...)   // live read caller

Error model

  • Read callers — return Promise<Result<T, QubicRpcError>>. Never throw.
  • Builders — throw PayloadBuildError synchronously on bad input.
  • Decoders — throw PayloadDecodeError on malformed bytes.

Installation

bun add @qubic.org/contracts
npm install @qubic.org/contracts
pnpm add @qubic.org/contracts

API reference

PageWhat's covered
NamespacePer-contract namespace objects — qearn, qx, qvault, etc.
Buildersbuild{Contract}{Procedure}Input — encode inputs to binary
Decodersdecode{Contract}{Procedure}Output — decode response bytes
Callers{contract}{Function} — typed live read functions
callContractFunctionLow-level primitive for unlisted contracts

Supported contracts

IndexNameProceduresFunctions
1Qx75
2Quottery178
3Random10
4QUtil139
5MyLastMatch00
6GeneralQuorumProposal25
7SupplyWatcher00
8ComputorControlledFund27
9Qearn28
10QVAULT1220
11MsVault916
12Qbay179
13Qswap118
14Nostromo910
15Qdraw12
16RandomLottery310
17QBond88
18QIP31
19QRaffle89
20qRWA614
21QReservePool42
22QThirtyFour811
23QDuel76
24Pulse1314
25VottunBridge87
26Qusino85
27Escrow52
27 contracts active · registry last updated May 16, 2026

Examples

Read a contract function

import { qearn } from "@qubic.org/contracts"
import { createLiveClient } from "@qubic.org/rpc"
import { identityToPublicKey, publicKeyToIdentity } from "@qubic.org/crypto"

const live = createLiveClient()
const converters = { identityToPublicKey, publicKeyToIdentity }

const result = await qearn.getStateOfRound(live, { epoch: 213 }, converters)

if (!result.ok) {
  console.error("RPC error:", result.error.status, result.error.message)
  process.exit(1)
}
console.log("Round state:", result.value)

Build a smart contract transaction

import { qearn } from "@qubic.org/contracts"
import { createWallet, generateSeed } from "@qubic.org/wallet"
import { createLiveClient } from "@qubic.org/rpc"
import { toIdentity } from "@qubic.org/types"

const live   = createLiveClient()
const wallet = createWallet(generateSeed())
const { tick } = await live.getTickInfo()

const payload     = qearn.buildLockInput({ amount: 10_000_000n })
const destination = toIdentity("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")

const { encoded, hash } = await wallet.buildScTransaction({
  destination,
  amount: 10_000_000n,
  targetTick: tick + 5,
  currentTick: tick,
  inputType: qearn.LOCK_INPUT_TYPE,
  payload,
})

const result = await live.broadcastTransaction(encoded)
console.log(`TX ${hash} broadcast to ${result.peersBroadcastedTo} peers`)

Decode historical output from archive

import { decodeQearnLockOutput } from "@qubic.org/contracts"
import { publicKeyToIdentity } from "@qubic.org/crypto"
import { createQueryClient } from "@qubic.org/rpc"
import { toTxHash } from "@qubic.org/types"

const archive = createQueryClient()
const tx = await archive.getTransaction(toTxHash("abcdef..."))

const output = decodeQearnLockOutput(
  Buffer.from(tx.responseData ?? "", "base64"),
  publicKeyToIdentity,
)
console.log("Lock output:", output)

On this page