signTransaction
Sign, encode to base64, verify, and hash transactions.
signTransaction(unsigned, seed)
Signs the unsigned transaction bytes from buildTransaction with a SchnorrQ signature, and appends the 64-byte signature to the end.
import { buildTransaction, signTransaction } from "@qubic.org/tx"
import { toSeed } from "@qubic.org/types"
const seed = toSeed("...")
const unsigned = buildTransaction({ ... })
const signed: Uint8Array = await signTransaction(unsigned, seed)
// signed = unsigned (≥80 B) + signature (64 B)signTransaction is async — it delegates to sign in @qubic.org/crypto. Always await it.
Parameters
| Name | Type | Description |
|---|---|---|
unsigned | Uint8Array | Output of buildTransaction |
seed | Seed | 55-character lowercase seed |
Returns Promise<Uint8Array> — signed transaction bytes (header + payload + 64-byte signature).
encodeTransaction(signed)
Base64-encodes signed transaction bytes for the RPC broadcast endpoint.
import { encodeTransaction } from "@qubic.org/tx"
const encoded: Base64 = encodeTransaction(signed)
await live.broadcastTransaction(encoded)Returns Base64 — standard base64 string.
hashTransaction(signed)
Computes the canonical transaction hash: K12 of the signed bytes, returned as a 60-character lowercase hex TxHash. Use this to look the transaction up in the archive after broadcasting.
import { hashTransaction } from "@qubic.org/tx"
const hash: TxHash = hashTransaction(signed)
const result = await archive.getTransaction(hash)Returns TxHash
verifyTransaction(signed, publicKey)
Verifies the SchnorrQ signature on a signed transaction against the provided public key.
import { verifyTransaction } from "@qubic.org/tx"
import { publicKeyFromSeed } from "@qubic.org/crypto"
const publicKey = publicKeyFromSeed(seed)
const valid: boolean = await verifyTransaction(signed, publicKey)Returns Promise<boolean> — true if the signature is valid for the given public key.
Complete sign-and-broadcast flow
import { buildTransaction, signTransaction, encodeTransaction, hashTransaction } from "@qubic.org/tx"
import { publicKeyFromSeed } from "@qubic.org/crypto"
import { toSeed } from "@qubic.org/types"
import { createLiveClient } from "@qubic.org/rpc"
const live = createLiveClient()
const seed = toSeed(process.env.SEED!)
const { tick } = await live.getTickInfo()
const unsigned = buildTransaction({
sourcePublicKey: publicKeyFromSeed(seed),
destinationPublicKey: new Uint8Array(32),
amount: 0n,
targetTick: tick + 5,
inputType: 0,
inputSize: 0,
})
const signed = await signTransaction(unsigned, seed)
const encoded = encodeTransaction(signed)
const hash = hashTransaction(signed)
await live.broadcastTransaction(encoded)
console.log("TX hash:", hash)