’m developing an escrow-style contract that needs to both receive and later release coins using the documented methods:
-
receive(coin: CoinInfo)– for receiving assets -
send(input: QualifiedCoinInfo, recipient: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>)– for sending assets back out
The contract successfully receives coins, but I’m currently blocked on releasing them, because the send() method requires a QualifiedCoinInfo, which includes the coin’s mt_index (Merkle tree index).
The documentation confirms that:
-
When the contract receives a coin, the runtime or indexer already knows the
mt_indexwhere the coin’s commitment was inserted. -
DApps are expected to save this information by calling
queryContext.insertCommitment(commitment, index)while assembling or validating the transaction.
However, there is currently no documented or programmatic way to retrieve this mt_index (or the commitment) off-chain after the coin has been received.
Without access to that, it’s impossible to construct a valid QualifiedCoinInfo, and therefore the contract cannot spend or release assets it holds.
Could you please clarify:
-
How can a DApp obtain the
mt_index(Merkle tree index) for a coin commitment after it’s received by a contract? -
Is there a current or planned indexer or runtime API that exposes this information (e.g., something like
getCommitmentIndex(commitment))? -
If the expectation is to use
insertCommitment()in theQueryContext, can you provide a code example or guidance on how to access or compute the commitment and index during transaction assembly?
This functionality is critical for implementing escrow and other asset-holding contract patterns. Right now, it seems there’s no viable way to release assets once they are held by a contract.
Thank you for clarifying — I’d really appreciate any example or best practice you can share for constructing a valid QualifiedCoinInfo in this context.