Type script that identifies this Coin asset.
Client used for all network requests.
Optionalfilter?: ClientIndexerSearchKeyFilterLike | nullCustom indexer filter. Defaults to cells with this type script
and outputDataLenRange: [16, ∞).
Cell deps automatically added to every built transaction.
ReadonlyscriptType script that identifies this Coin.
ReadonlyclientReadonlyfilterIndexer 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.
StaticbalanceReads the Coin balance 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 balanceFrom.
Aggregates Coin info (balance, 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 balance.
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 (balance, capacity, count) for all Coin inputs in the transaction.
Convenience wrapper around getInputsInfo that returns only the balance.
Returns aggregated Coin info (balance, capacity, count) for all Coin outputs in the transaction.
Convenience wrapper around getOutputsInfo that returns only the balance.
Returns inputs minus outputs as a CoinInfo. Positive balance means tokens are burned;
positive capacity means Coins provide surplus CKB.
Convenience wrapper around getInfoBurned that returns only the balance (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 both the Coin balance gap and the CKB capacity gap are covered.
OptionalbalanceTweak: NumLike | nullExtra Coin balance to require beyond what outputs consume.
OptionalcapacityTweak: NumLike | nullExtra CKB capacity to require beyond what outputs consume.
Low-level completion primitive. Adds Coin inputs, then calls change(tx, balance) to
write the change output. change is called twice: once on a clone to measure the extra
capacity the change cell needs, and once on the real transaction with the final balance.
Callback that receives the transaction and the excess Coin balance, and
should write the change output in place. Must be side-effect-free beyond modifying tx.
Optionaloptions: { shouldAddInputs?: boolean | null }OptionalshouldAddInputs?: boolean | nullWhen false, skips input sourcing entirely and calls
change once with the current balance. Defaults to true.
Completes the transaction by writing the excess Coin balance into the existing output at
index. The output must already be a valid Coin cell with this type script.
Optionaloptions: {OptionalshouldAddInputs?: boolean | nullOptionaltransformer?: ((cell: CellAny) => CellAnyLike | Promise<CellAnyLike>) | nullOptional callback to further modify the change cell after the
balance has been written into outputData[0..16). Receives the updated cell and returns
the final cell. Any capacity below the data minimum is raised automatically; capacity
above the minimum is preserved as-is. The transformer runs on every change call, so
it must be idempotent with respect to data layout.
Completes the transaction by creating a new change output locked to changeLike.
Optionaloptions: {OptionalshouldAddInputs?: boolean | nullOptionaltransformer?: ((cell: CellAny) => CellAnyLike | Promise<CellAnyLike>) | nullOptional callback to further modify the change cell after the
balance has been encoded into outputData[0..16). Use this to append protocol-specific
data or reserve extra capacity.
Convenience wrapper around completeChangeToLock using the signer's recommended address.
Optionaloptions: {const { tx: completedTx } = await coin.completeBy(tx, signer);
await completedTx.completeInputsByCapacity(signer);
await completedTx.completeFeeBy(signer);
await signer.sendTransaction(completedTx);
completeChangeToLock for more control over the change destination.
A generic on-chain Coin (fungible token) identified by a CKB type script.
Provides helpers for querying balances and building/completing transactions. Asset identity is defined by the complete type script
(codeHash, hashType, args)— only cells with an identical type script belong to the same Coin.