refactor: use getAction internally
As an author of custom actions and action overrides, I will use viem actions internally but sometimes forget to call them getAction so that the actions can compose on one another.
For example, maybe I'll use getChainId internally in my custom action, but I want this to be composable with an action that overrides getChainId to cache the RPC's chain ID. If I don't call this with getAction, I'll accidentally bypass this cache and viem will do the underlying RPC call.
I've seen this pattern in both in my code, other SDKs, and within viem itself.
I am curious if, instead of requiring all action authors to use getAction, that viem itself exports by default the getAction-wrapped variant of each of these actions, while also exporting the internal implementation in case it's useful to make an explicit, direct call.
I'm mocking this up here to see if this approach seems reasonable before doing more because its quite a big refactor.
PR-Codex overview
This PR focuses on refactoring functions in various action files to directly call getBlock, getBlockNumber, and getChainId functions instead of using getAction.
Detailed summary
- Replaced
getActioncalls with direct calls togetBlock,getBlockNumber, andgetChainIdfunctions in multiple files. - Updated function signatures and parameters accordingly.
- Removed unnecessary
getActionimports from specific files.
✨ Ask PR-Codex anything about this PR by commenting with
/codex {your question}
⚠️ No Changeset found
Latest commit: 9d97e93f581587bf0b684f8c6c072f1658b90a05
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
@holic is attempting to deploy a commit to the Wevm Team on Vercel.
A member of the Team first needs to authorize it.
means third party actions will also need to remember to implement it
this is already true for getAction today, which isn't correctly used in most cases
So if I have two decorators that each override getChainId, only the most recently used one (called via .extend) will be attached to the client and called by all other actions.
Which makes sense, because the action ultimately calls out to another lower level action or RPC method.
I have a use case where I override writeContract to allow submitting txs to the mempool serially to ensure nonce ordering. In this action, I wanted to internally call whatever the underlying writeContract action is on the client, to preserve original behavior. But that would be my own writeContract if you extended the client with this action, rather than the one attached before it?
Nevermind, it does work like a stack of middleware. Test PR coming!
closing for now – will revisit later