Compact<u64>
Compact 178 v411About This Type
Variable-length encoded wrapper around u64.
Compact encoding uses fewer bytes for small values. Values 0–63 use 1 byte, 64–16,383 use 2 bytes, and larger values use 4 bytes.
Encoding: Two least-significant bits encode the mode: 00=single-byte, 01=two-byte, 10=four-byte, 11=big-integer.
Compact Wrapper
- Wraps
- u64
- SCALE Encoding
- Variable-length integer (1, 2, or 4 bytes depending on value)
SCALE Encoding
- Rule
- Variable-length integer encoding of u64. Uses fewer bytes for smaller values.
- Size
- variable (1–5 bytes)
Examples
Small value: 6 = 6
0x1818 Single-byte mode: 6 << 2 = 24 = 0x18Medium value: 100 = 100
0x910191 01 Two-byte mode: (100 << 2) | 0x01 = 401 = 0x0191, stored LELarger value: 1,000,000 = 1,000,000
0x02000f400202 00 0f 40 02 Four-byte mode: (1,000,000 << 2) | 0x02Code Examples
import { TypeRegistry, compactToU8a } from "@polkadot/types";
const registry = new TypeRegistry();
// Encode as Compact<u64>
const value = registry.createType("Compact<u64>", 100);
console.log("Hex:", value.toHex());
// Or use the low-level utility
const bytes = compactToU8a(100);
console.log("Bytes:", bytes);Referenced By (29)
#11 Weight via ref_time#11 Weight via proof_size#135 Timestamp::Call via set.now#175 Balances::Call via transfer_allow_death.value#175 Balances::Call via force_transfer.value#175 Balances::Call via transfer_keep_alive.value#175 Balances::Call via force_set_balance.new_free#175 Balances::Call via force_adjust_total_issuance.delta#175 Balances::Call via burn.value#239 Vec<Compact<u64>> #432 Crowdloan::Call via create.deposit#432 Crowdloan::Call via create.min_contribution#432 Crowdloan::Call via create.cap#432 Crowdloan::Call via contribute.amount#432 Crowdloan::Call via update_min_contribution.new_min_contribution#432 Crowdloan::Call via update_cap.new_cap#435 Contracts::Call via call_old_weight.value#435 Contracts::Call via call_old_weight.gas_limit#435 Contracts::Call via instantiate_with_code_old_weight.value#435 Contracts::Call via instantiate_with_code_old_weight.gas_limit
and 9 more...
Type Information
- Type ID
- 178
- Kind
- Compact
- Runtime
- v411