A Qubic contract call is a byte string. One wrong offset can still produce a well-formed call, and the contract may accept it and write the wrong value.
Glyph Contracts generates the metadata, ABI descriptors, and binary codecs from qubic/core. The TypeScript package gives application code the same layouts the contracts use on chain.
What the package contains
- Metadata for every production contract
- Procedures, functions, notifications, structs, and enums
- Exact on-chain memory layout and padding
- Encoders and decoders for procedure and function inputs and outputs
The generated metadata records the procedures and functions in each contract, along with the structs, enums, and fields they use. The codecs turn typed values into the bytes a contract expects, including the padding that C++ alignment adds.
The package is published as @glyph-oss/contracts and is regenerated from qubic/core once a week. A pull request is opened only when the ABI hash changes.
Encode a QX call
Install the package:
bun add @glyph-oss/contracts
The typed handle keeps the contract name, call name, and field layout together:
import { QX } from "@glyph-oss/contracts";
const payload = QX.encodeProcedure("IssueAsset", {
assetName: 1n,
numberOfShares: 1_000_000n,
unitOfMeasurement: 1n,
numberOfDecimalPlaces: 0,
});
const issued = QX.decodeProcedureOutput("IssueAsset", outputBytes);
console.log(issued.issuedNumberOfShares);
outputBytes is the raw output struct returned by the contract. The decoder applies the same field order and padding used by the encoder, so the result arrives as typed values instead of an offset map.
A working sequence
- 1Find the contract and call in the generated metadata.
- 2Encode the input with the typed handle or the low-level contract call helper.
- 3Send the payload through the Qubic client your service already uses.
- 4Decode the returned bytes with the matching output codec.
The low-level helpers accept a contract definition and call ordinal when the metadata comes from an external source. Application code should use the typed handles such as QX; they reduce the chance of pairing the wrong input with the wrong output.
Function results work the same way:
const fees = QX.decodeFunctionOutput("Fees", feesBytes);
console.log(fees.assetIssuanceFee, fees.transferFee, fees.tradeFee);
The package does not replace a Qubic client. It supplies the contract definitions and byte handling around the client, so the call you build matches the contract that will execute it.
@glyph-oss/contracts on npmInstall the package and browse the generated contract exports. Contracts sourceGenerated types and codecs on GitHub.