-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RPC-only transaction confirmation support #110
base: main
Are you sure you want to change the base?
Add RPC-only transaction confirmation support #110
Conversation
🦋 Changeset detectedLatest commit: 197186d The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -0,0 +1,201 @@ | |||
/* eslint-disable sort-keys-fix/sort-keys-fix */ | |||
/** | |||
* EXAMPLE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied and minimally changed the existing example.ts
to demonstrate the new RPC-only functionality.
@@ -143,7 +149,7 @@ try { | |||
} | |||
``` | |||
|
|||
### `sendTransactionWithoutConfirmingFactory({rpc, rpcSubscriptions})` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected this error (the method doesn't actually accept an rpcSubscriptions
parameter).
packages/library/src/__typetests__/send-and-confirm-transaction-typetests.ts
Outdated
Show resolved
Hide resolved
packages/transaction-confirmation/src/__tests__/confirmation-strategy-blockheight-test.ts
Outdated
Show resolved
Hide resolved
1696ea8
to
21cbdf9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tl;dr web3.js 2.0 doesn't do ‘modes.’
sendAndConfirmTransactionFactory()
is already a super thin wrapper around createBlockHeightExceedencePromiseFactory()
. I would totally consider including a new confirmer, that describes your new strategy, and implements your polling code.
const sendAndPollToConfirm = sendAndPollToConfirmTransactionFactory({
interval: 1000,
rpc,
});
await Promise.all([ | ||
let currentBlockHeight: bigint; | ||
|
||
if (rpcSubscriptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this does is to create dead code, no matter which way you use this confirmation strategy. If you use subscriptions, all of the polling code is dead. If you use polling, all of the subscriptions code is dead. You get the dead code in your JS bundle unconditionally, which reduces package efficiency.
In short, ‘modes’ are bad, because they create dead code and reduce package efficiency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, that's fair. I'll extract these changes into a separate confirmer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@steveluscher Please see the updated changeset.
Add `sendAndPollToConfirmTransactionFactory` as a WebSocket-free alternative for transaction confirmation. This implementation uses polling instead of subscriptions, making it suitable for environments where WebSocket connections are unavailable or undesired. Key changes: - Add new `sendAndPollToConfirmTransactionFactory` with configurable polling interval - Implement block height and signature status polling strategies - Add comprehensive tests for new polling mechanisms - Update documentation with usage examples - Add new example demonstrating RPC-only transaction confirmation
21cbdf9
to
d246964
Compare
rpc, | ||
pollingInterval, | ||
}: SendAndPollToConfirmTransactionWithBlockhashLifetimeFactoryConfig<'mainnet'>): SendAndPollToConfirmTransactionWithBlockhashLifetimeFunction; | ||
export function sendAndPollToConfirmTransactionFactory< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gist of this PR.
Problem
Transaction confirmation currently requires WebSocket connections, which may not be available or desired in all environments. And there's no documented way to use the transaction confirmation functionality with just RPC (HTTP) polling.
As the great Rich Hickey said:
The 2.0 API shouldn't break use cases by requiring a Websocket where only having an RPC connection will suffice.
N.b. I'm not suggesting that RPC-only is technically superior. Just that it should be possible.
Summary of Changes
rpcSubscriptions
parameter optional insendAndConfirmTransactionFactory