Skip to content
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

If the user doesn't specify a lifetime, add a recent blockhash before sending. #1694

Closed
mikemaccana opened this issue Oct 6, 2023 · 3 comments
Labels
enhancement New feature or request stale

Comments

@mikemaccana
Copy link
Contributor

Motivation

Most transactions made with web3.js will need a recent blockhash. This means every time a developer makes a transaction they have to add some boilerplate code.

Rather than require users to specify a recent blockhash or durable nonce every time they create a new transaction, the user should be able to omit a recent blockhash and, in this case, a recent blockhash should be found added to the transaction when submitted.

🤔 I'm concerned that this will affect perceived transaction times as sends will include the time taken to get a recent blockhash.

However the reduction in unnecessary boilerplate may be considered worth this, and we can ensure that docs reflect that users should get a recent blockhash in advance of sending their transaction for optimum speeds.

Very keen to find out what others think here.

Example use case

Before

const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();

...
setTransactionLifetimeUsingBlockhash(latestBlockhashResult.latestBlockhash, transaction)

After

(nothing, a blockhash is created when a user doesn't specify the lifetime)

Details

Essentially this switches explicitly getting lifetimes from being mandatory boilerplate to a performance optimisation.

@mikemaccana mikemaccana added the enhancement New feature or request label Oct 6, 2023
@mcintyre94
Copy link
Contributor

This is a tricky one for a similar reason to changing the name of sendTransaction. All our RPC methods are precisely consistent with the JSON RPC in behaviour as well as name, all they do it pass their params in a JSON RPC request. And again this is both implementation detail and kinda unavoidable (for the low level rpc-core library) because of the proxy implementation. It's not currently possible for us to make an rpc-core function do something other than send a JSON RPC request with its params.

I wonder if the best approach here might be a higher-level library that sits above both rpc-core and transactions, and contains helpers for creating transactions (your #1693 issue) and for sending them, including something like this that adds a default blockhash before serializing and calling sendTransaction?

@mikemaccana
Copy link
Contributor Author

Thanks @mcintyre94 that makes sense:

  • rpc-core is a 1:1 match of the RPC's own functions and behaviour
  • A higher level library that provides common defaults, to avoid boilerplate, focused on end-user productivity.

Copy link
Contributor

Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

2 participants