-
-
Notifications
You must be signed in to change notification settings - Fork 842
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 Custom Chain Serializers #691
Conversation
🦋 Changeset detectedLatest commit: fb23b42 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 |
Someone is attempting to deploy a commit to the wagmi Team on Vercel. A member of the Team first needs to authorize it. |
a272748
to
a2359ae
Compare
EDIT: fixed by #709 One issue Im running into is that the TS types for the return values of functions are very specific only allowing for specific strings. for instance type TransactionSerialized<TType extends TransactionType = 'legacy'> =
| (TType extends 'eip1559' ? TransactionSerializedEIP1559 : never)
| (TType extends 'eip2930' ? TransactionSerializedEIP2930 : never)
| (TType extends 'legacy' ? TransactionSerializedLegacy : never) and export type GetTransactionType<
TTransactionSerializable extends TransactionSerializable = TransactionSerializable,
> =
| (TTransactionSerializable['maxFeePerGas'] extends bigint
? 'eip1559'
: never)
| (TTransactionSerializable['maxPriorityFeePerGas'] extends bigint
? 'eip1559'
: never)
| (TTransactionSerializable['gasPrice'] extends bigint
? TTransactionSerializable['accessList'] extends AccessList
? 'eip2930'
: 'legacy'
: never)
| (TTransactionSerializable['type'] extends string
? TTransactionSerializable['type']
: never)
exampleIt seems like the solution will be for |
a2359ae
to
58529aa
Compare
ive writen up what I hope to be a doc on how to use this but Im not sure where in the docs it should go Using custom transaction serializerFor Local Accounts ::: code-group import { account, walletClient } from './config'
import { serializer } from './serializer'
const signedTransaction = await account.signTransaction(transaction, serializer) import { SerializeTransactionFn, serializeTransaction } from 'viem/utils'
import { TransactionSerializable } from 'viem/types'
type CustomTX = TransactionSerializable {
type: 'pip112' // a string representing the tx type this should serialize to a EIP2718 compliant TransactionType https://eips.ethereum.org/EIPS/eip-2718#transactiontype-only-goes-up-to-0x7f
extraField: // some field the spec for this tx type supports
}
export const serializer: SerializeTransactionFn<CustomTX> = (transaction) => {
if (specialCase(transaction)) {
// serialization code here
} else {
return serializeTransaction(transaction)
}
} |
@aaronmgdr I'm sorry, I cannot determine the PR number or link from the code diff provided. Please provide the PR number or link so that I can show you the changes made by the PR. |
/codex summarize PR #691 |
@aaronmgdr PR #691 adds support for EIP-2930 access lists to the |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
f14eb78
to
a399dd6
Compare
Codecov Report
@@ Coverage Diff @@
## main #691 +/- ##
==========================================
- Coverage 99.80% 95.02% -4.79%
==========================================
Files 250 247 -3
Lines 23841 23660 -181
Branches 2055 1748 -307
==========================================
- Hits 23795 22482 -1313
- Misses 43 1167 +1124
- Partials 3 11 +8
|
df92e1e
to
c7fb925
Compare
TLDR
Allow account.signTransaction to take an optional transactionSerializer argument.
##Why?
Through custom chain formatters viem supports alternative standards. for formatting transactions but not yet for signing them
How
add to signTransaction an optional argument for a serializer which
add an optional
serializer
property to chain.if the current chain has a serializer pass as argument to signTransaction function.
It is recommended that custom serializers check if the transaction is the type they support and if not call the default viem serializeTransaction function.
Example
// create a customer Serializer ie
// Add it to the chain
other ways to achieve this
technically its possible to add an custom serializer by creating an account using the
toAccount
function.This has 2 limitations.
you must recreated the
privateKeyToAccount
,signTransaction
just to modify theserializeTransaction
function. SincemneumonicToAccount
andHDKeyToAccount
use privateKeyToAccount they must also be recreated.it doesnt give an elegent way for there to be multiple serializers such as different chains both having custom serializers.
related PRS
supersedes #666
PR-Codex overview
This PR adds support for custom chain serializers and EIP-2930 access lists. It also makes changes to several files, including
utils
,types
,accounts
,actions
, andtransaction
.Detailed summary
chain.serializers
serializeTransaction
from someutils
filessignTransaction
inaccounts/utils/signTransaction.ts
serializeTransaction
inutils/transaction/serializeTransaction.ts
Account
type inaccounts/types.ts
Chain
type intypes/chain.ts
serializeAccessList
andsignTransaction