ProtectedconstructorInternal
ReadonlyscriptType script that identifies this Coin.
Optional ReadonlytransformerOutput transformer for Coin outputs.
ReadonlycoCoBuild instance for this Coin.
ReadonlyclientClient for network requests.
ReadonlyfilterIndexer search filter used to find Coin cells.
Defaults to cells with this type script and outputDataLenRange: [16, ∞).
ReadonlycellCell deps required by the type script, added to every built transaction.
ReadonlyargsParsed and normalized xUDT type args.
If xUdtArgs was provided, this is the normalized form of that value. If
only script.args was provided, this is parsed from the existing args.
ProtectedshouldInternal
Whether Coin inputs should also be used to cover missing CKB capacity.
StaticamountReads the Coin amount from raw output data without verifying the type script.
Returns 0 if the data is shorter than 16 bytes.
⚠️ The caller must ensure the data belongs to a valid Coin cell.
For safe extraction from an arbitrary cell use amountFrom.
Applies the configured output transformer to a transaction output.
Writes a Coin amount into a transaction output and applies the configured transformer for that output.
The amount is encoded as a 16-byte little-endian integer at
outputData[0..16). Any bytes after the first 16 are preserved, which lets
callers keep extension data attached to token cells.
Transaction containing the output.
Index of the output to update.
Coin amount to write into outputData[0..16).
The transformed transaction.
Aggregates Coin info (amount, capacity, count) from cells, skipping non-Coins. Accepts a single cell, a sync iterable, or an async iterable.
Optionalacc: CoinInfoLikeConvenience wrapper around infoFrom that returns only the amount.
Optionalacc: NumLike | nullScans all Coins owned by the signer and returns aggregated info.
Optionaloptions: { source?: "chain" | "local" | null }
Optionalsource?: "chain" | "local" | null"chain" (default) queries on-chain state; "local" uses the
local indexer cache which is faster but may be stale.
⚠️ Expensive — scales linearly with the number of Coin cells.
Convenience wrapper around calculateInfo that returns only the balance.
⚠️ Expensive — scans all Coin cells owned by the signer.
Optionaloptions: { source?: "chain" | "local" | null }Returns whether the cell is a valid Coin for this token. Subclasses may override this to apply additional validation rules.
Returns aggregated Coin info (amount, capacity, count) for all Coin inputs in the transaction.
Convenience wrapper around getInputsInfo that returns only the amount.
Returns aggregated Coin info (amount, capacity, count) for all Coin outputs in the transaction.
Convenience wrapper around getOutputsInfo that returns only the amount.
Returns inputs minus outputs as a CoinInfo. Positive amount means tokens are burned;
positive capacity means Coins provide surplus CKB.
Convenience wrapper around getInfoBurned that returns only the amount (inputs − outputs).
Low-level input selector driven by a custom accumulator.
For each candidate Coin cell the accumulator receives (state, cell, coinInfo) and
returns the next state to keep going, or undefined to stop.
accumulated is undefined if the target was reached before all cells were visited.
Adds Coin inputs until the Coin amount gap is covered. When
shouldUseCoinsForCapacity is enabled, it also attempts to cover the CKB capacity gap
on a best-effort basis (capacity may still be negative if Coin inputs are exhausted
before it is satisfied).
OptionaltxLike: TransactionLike | nullOptionalamountTweak: NumLike | null
Extra Coin amount to require beyond what outputs consume.
OptionalcapacityTweak: NumLike | null
Extra CKB capacity to require beyond what outputs consume.
Adds ALL available Coins from the signer as inputs. Useful for consolidation or full sweeps.
OptionaltxLike: TransactionLike | nullLow-level completion primitive. Adds Coin inputs, then calls change(tx, amount) to
write the change output.
complete never manages CKB capacity on its own — it only opportunistically uses any
capacity gap between inputs and outputs to merge Coin cells (reducing the number of
Coin inputs added), on a best-effort basis. It does not guarantee tx has enough
capacity afterwards; follow up with tx.completeBy (or similar) to complete capacity.
Callback that receives the transaction and the excess Coin amount, writes
the change output, and returns the resulting transaction. It must be side-effect-free
beyond modifying tx, as it may be invoked more than once (e.g. speculatively on a clone)
before being applied to the final transaction.
OptionaltxLike: TransactionLike | nullOptionaloptions: { shouldAddInputs?: boolean | null }
OptionalshouldAddInputs?: boolean | nullWhen false, skips input sourcing entirely; the caller
is responsible for ensuring tx already has enough Coin inputs. Defaults to true.
Completes the transaction by writing the excess Coin amount into the existing output at
index. The output must already be a valid Coin cell with this type script.
OptionaltxLike: TransactionLike | nullOptionaloptions: { shouldAddInputs?: boolean | null }Completes the transaction by creating a new change output locked to changeLike.
OptionaltxLike: TransactionLike | nullOptionaloptions: { shouldAddInputs?: boolean | null }Convenience wrapper around completeChangeToLock using the signer's recommended address.
Optionaltx: TransactionLike | nullOptionaloptions: { shouldAddInputs?: boolean | null }const completedTx = await coin.completeBy(signer, tx);
await completedTx.completeFeeBy(signer);
await signer.sendTransaction(completedTx);
completeChangeToLock for more control over the change destination.
Make the transaction perform transfer actions to the specified recipients.
OptionaltxLike: TransactionLike | nullThe updated transaction with added transfer outputs and CoBuild actions.
Make the transaction perform mint actions to the specified recipients.
OptionaltxLike: TransactionLike | nullThe updated transaction with added mint outputs and CoBuild actions.
Make the transaction perform burn actions for the specified amount.
OptionaltxLike: TransactionLike | nullThe updated transaction with appended CoBuild actions.
StaticnewCreates an xUDT coin helper.
xUdtArgs takes priority over script.args for the final type script args.
A complete script takes priority over knownScript; otherwise the known
script shorthand defaults to ccc.KnownScript.XUdt.
Protected StaticresolveInternal
Resolves xUDT args and asynchronous Coin dependencies.
An extensible UDT (xUDT) Coin implementation.
CoinXUdtis a small specialization of Coin that understands the xUDT type args layout from RFC 52. It keeps the generic balance, transfer, and transaction completion behavior fromCoin, while exposing the parsed xUDT args via CoinXUdt.args.Example