Skip to main content

Value

Pebble 0.3.1 · all symbols on this page are stable.

A multi-asset bundle: zero or more (PolicyId, TokenName) → amount entries. Maps to Plutus Core's native value type. ADA appears under a special "ada/lovelace" policy.

Every TxOut.value, Tx.mint, and Tx.fee is a Value.

const out = tx.outputs[0];
assert out.value.lovelaces() >= 2_000_000;
assert out.value.amountOf(myPolicy, myToken) == 1;

Methods

MethodDescription
amountOf(policy: PolicyId, name: TokenName): intAmount of (policy, name). 0 if absent.
lovelaces(): intAmount of ADA, in lovelace.
insert(policy: PolicyId, name: TokenName, amount: int): ValueReturn a new Value with (policy, name) set to amount. 0 removes.
union(other: Value): ValueAsset-wise sum.
contains(other: Value): boolTrue iff self ≥ other for every asset.
scale(k: int): ValueMultiply every amount by k.
toData(): dataCBOR-encode. Auto-derived from ToData.

Examples (one per method)

const v: Value = mempty.insert(myPolicy, myToken, 5);

const a: int = v.amountOf(myPolicy, myToken); // 5
const l: int = tx.outputs[0].value.lovelaces(); // ADA in lovelace
const v2: Value = v.insert(myPolicy, myToken, 10); // overwrite -> 10
const u: Value = v.union(v); // 2× v
const ok: bool = u.contains(v); // true
const s: Value = v.scale(3); // 3× v
const d: data = v.toData();

Bundled example

const need = mempty
.insert(myPolicy, myToken, 1)
.insert(adaPolicy, adaName, 2_000_000);

assert tx.outputs[0].value.contains(need);

Operators

CategoryOperators
Equality==, != (structural)

Building values

There's no Value literal — build values up from an empty starting point (mempty from the prelude) using insert and union, or destructure them out of a TxOut. The underlying primitives are in std.builtins (insertCoin, unionValue, etc.); the friendlier names live in std.value.

See also