feat(cdm): expose waitFor option on contract tx() calls#12
Open
shawntabrizi wants to merge 1 commit into
Open
Conversation
Adds an optional `waitFor: "best-block" | "finalized"` field to TxOpts. When omitted, behavior is unchanged (waits for finalization). Setting to "best-block" resolves the Promise as soon as the tx is included in a block, which is typically 5-10x faster on chains with slow GRANDPA finality (local zombienet, dev networks). Implementation: switch from PAPI's signAndSubmit (which has no waitFor knob) to submitAndWatch from @polkadot-apps/tx. submitAndWatch already handles InkSDK's AsyncTransaction wrapper transparently via its `.waited` Promise, so the existing `tx` from `papiContract.send(...)` flows through unchanged. Motivated by a local dev loop where each .tx() call took 12-18s waiting for finalization, masking the actual ~2s block time and making play-test-fix iteration painful. With waitFor: "best-block" the same tx returns in ~2s. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
waitFor: \"best-block\" | \"finalized\"field toTxOpts. When omitted, behavior is unchanged (waits for finalization). Setting to\"best-block\"resolves the Promise as soon as the tx is included in a block — typically 5-10× faster on chains with slow GRANDPA finality (local zombienet, dev networks).Motivation
While building a Triangle game on top of
@dotdm/cdmagainst a local PPN zombienet, everyarena.method.tx(...)call took 12-18s to resolve, even though Asset Hub blocks tick every ~2s. The bottleneck wassignAndSubmitalways waiting for finalization.For local dev where finality guarantees aren't needed, sub-second tx feedback materially improves the play-test-fix loop. Real-game gameplay code becomes:
…and the perceived latency drops from ~30s per click to ~2s.
Changes
types.ts: addwaitFor?: \"best-block\" | \"finalized\"toTxOptswith docstringwrap.ts: replaceawait tx.signAndSubmit(signer)withawait submitAndWatch(tx, signer, { waitFor }).submitAndWatchfrom@polkadot-apps/txalready handles InkSDK'sAsyncTransactionwrapper via its.waitedPromise, so passingpapiContract.send(...)directly flows through unchanged.package.json: add@polkadot-apps/txto deps (already in the catalog via@dotdm/contracts)Backwards compatibility
waitFordefaults to\"finalized\", so any caller that doesn't pass it gets identical behavior. TheTxResultshape ({ txHash, blockHash, ok, events }) is unchanged.Related
Test plan
pnpm installresolvespnpm --filter \"@dotdm/cdm\" buildcleanwaitFor: \"best-block\"returns in ~2s vs ~15s for default "finalized"🤖 Generated with Claude Code