Skip to content

Commit e0fb782

Browse files
committed
feat: add action context to formatters; tweak tx types
1 parent cce7f03 commit e0fb782

23 files changed

Lines changed: 196 additions & 130 deletions

src/accounts/utils/signTransaction.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ describe('eip4844', async () => {
7070
blobVersionedHashes,
7171
chainId: 1,
7272
sidecars,
73+
to: '0x0000000000000000000000000000000000000000',
7374
type: 'eip4844',
7475
} as const satisfies TransactionSerializable
7576

@@ -84,7 +85,14 @@ describe('eip4844', async () => {
8485
test('args: blobs + kzg', async () => {
8586
const blobs = toBlobs({ data: stringToHex(blobData) })
8687
const signature = await signTransaction({
87-
transaction: { ...base, blobs, chainId: 1, kzg, type: 'eip4844' },
88+
transaction: {
89+
...base,
90+
blobs,
91+
chainId: 1,
92+
kzg,
93+
to: '0x0000000000000000000000000000000000000000',
94+
type: 'eip4844',
95+
},
8896
privateKey: accounts[0].privateKey,
8997
})
9098
expect(signature).toMatchSnapshot()
@@ -94,7 +102,7 @@ describe('eip4844', async () => {
94102
const blobs = toBlobs({ data: stringToHex(blobData) })
95103
const request = await prepareTransactionRequest(client, {
96104
account: privateKeyToAccount(accounts[0].privateKey),
97-
blobs: blobs,
105+
blobs,
98106
kzg,
99107
maxFeePerBlobGas: parseGwei('20'),
100108
to: '0x0000000000000000000000000000000000000000',

src/actions/public/call.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,26 @@ export async function call<chain extends Chain | undefined>(
226226
const chainFormat = client.chain?.formatters?.transactionRequest?.format
227227
const format = chainFormat || formatTransactionRequest
228228

229-
const request = format({
230-
// Pick out extra data that might exist on the chain's transaction request type.
231-
...extract(rest, { format: chainFormat }),
232-
from: account?.address,
233-
accessList,
234-
authorizationList,
235-
blobs,
236-
data,
237-
gas,
238-
gasPrice,
239-
maxFeePerBlobGas,
240-
maxFeePerGas,
241-
maxPriorityFeePerGas,
242-
nonce,
243-
to: deploylessCall ? undefined : to,
244-
value,
245-
} as TransactionRequest) as TransactionRequest
229+
const request = format(
230+
{
231+
// Pick out extra data that might exist on the chain's transaction request type.
232+
...extract(rest, { format: chainFormat }),
233+
from: account?.address,
234+
accessList,
235+
authorizationList,
236+
blobs,
237+
data,
238+
gas,
239+
gasPrice,
240+
maxFeePerBlobGas,
241+
maxFeePerGas,
242+
maxPriorityFeePerGas,
243+
nonce,
244+
to: deploylessCall ? undefined : to,
245+
value,
246+
} as TransactionRequest,
247+
'call',
248+
) as TransactionRequest
246249

247250
if (
248251
batch &&

src/actions/public/createAccessList.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,23 @@ export async function createAccessList<chain extends Chain | undefined>(
127127
const chainFormat = client.chain?.formatters?.transactionRequest?.format
128128
const format = chainFormat || formatTransactionRequest
129129

130-
const request = format({
131-
// Pick out extra data that might exist on the chain's transaction request type.
132-
...extract(rest, { format: chainFormat }),
133-
from: account?.address,
134-
blobs,
135-
data,
136-
gas,
137-
gasPrice,
138-
maxFeePerBlobGas,
139-
maxFeePerGas,
140-
maxPriorityFeePerGas,
141-
to,
142-
value,
143-
} as TransactionRequest) as TransactionRequest
130+
const request = format(
131+
{
132+
// Pick out extra data that might exist on the chain's transaction request type.
133+
...extract(rest, { format: chainFormat }),
134+
from: account?.address,
135+
blobs,
136+
data,
137+
gas,
138+
gasPrice,
139+
maxFeePerBlobGas,
140+
maxFeePerGas,
141+
maxPriorityFeePerGas,
142+
to,
143+
value,
144+
} as TransactionRequest,
145+
'createAccessList',
146+
) as TransactionRequest
144147

145148
const response = await client.request({
146149
method: 'eth_createAccessList',

src/actions/public/estimateGas.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,27 @@ export async function estimateGas<
165165
const chainFormat = client.chain?.formatters?.transactionRequest?.format
166166
const format = chainFormat || formatTransactionRequest
167167

168-
const request = format({
169-
// Pick out extra data that might exist on the chain's transaction request type.
170-
...extract(rest, { format: chainFormat }),
171-
from: account?.address,
172-
accessList,
173-
authorizationList,
174-
blobs,
175-
blobVersionedHashes,
176-
data,
177-
gas,
178-
gasPrice,
179-
maxFeePerBlobGas,
180-
maxFeePerGas,
181-
maxPriorityFeePerGas,
182-
nonce,
183-
to,
184-
value,
185-
} as TransactionRequest)
168+
const request = format(
169+
{
170+
// Pick out extra data that might exist on the chain's transaction request type.
171+
...extract(rest, { format: chainFormat }),
172+
from: account?.address,
173+
accessList,
174+
authorizationList,
175+
blobs,
176+
blobVersionedHashes,
177+
data,
178+
gas,
179+
gasPrice,
180+
maxFeePerBlobGas,
181+
maxFeePerGas,
182+
maxPriorityFeePerGas,
183+
nonce,
184+
to,
185+
value,
186+
} as TransactionRequest,
187+
'estimateGas',
188+
)
186189

187190
return BigInt(
188191
await client.request({

src/actions/public/getBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ export async function getBlock<
128128
if (!block) throw new BlockNotFoundError({ blockHash, blockNumber })
129129

130130
const format = client.chain?.formatters?.block?.format || formatBlock
131-
return format(block)
131+
return format(block, 'getBlock')
132132
}

src/actions/public/getTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,5 @@ export async function getTransaction<
148148

149149
const format =
150150
client.chain?.formatters?.transaction?.format || formatTransaction
151-
return format(transaction)
151+
return format(transaction, 'getTransaction')
152152
}

src/actions/public/getTransactionReceipt.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,8 @@ export async function getTransactionReceipt<chain extends Chain | undefined>(
6868
const format =
6969
client.chain?.formatters?.transactionReceipt?.format ||
7070
formatTransactionReceipt
71-
return format(receipt) as GetTransactionReceiptReturnType<chain>
71+
return format(
72+
receipt,
73+
'getTransactionReceipt',
74+
) as GetTransactionReceiptReturnType<chain>
7275
}

src/actions/test/sendUnsignedTransaction.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,23 @@ export async function sendUnsignedTransaction<
7272
const chainFormat = client.chain?.formatters?.transactionRequest?.format
7373
const format = chainFormat || formatTransactionRequest
7474

75-
const request = format({
76-
// Pick out extra data that might exist on the chain's transaction request type.
77-
...extract(rest, { format: chainFormat }),
78-
accessList,
79-
data,
80-
from,
81-
gas,
82-
gasPrice,
83-
maxFeePerGas,
84-
maxPriorityFeePerGas,
85-
nonce,
86-
to,
87-
value,
88-
} as TransactionRequest)
75+
const request = format(
76+
{
77+
// Pick out extra data that might exist on the chain's transaction request type.
78+
...extract(rest, { format: chainFormat }),
79+
accessList,
80+
data,
81+
from,
82+
gas,
83+
gasPrice,
84+
maxFeePerGas,
85+
maxPriorityFeePerGas,
86+
nonce,
87+
to,
88+
value,
89+
} as TransactionRequest,
90+
'sendUnsignedTransaction',
91+
)
8992
const hash = await client.request({
9093
method: 'eth_sendUnsignedTransaction',
9194
params: [request],

src/actions/wallet/prepareTransactionRequest.test-d.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ test('args: type', async () => {
113113
readonly BlobSidecar<`0x${string}`>[] | undefined
114114
>()
115115
expectTypeOf(result_eip4844.gasPrice).toEqualTypeOf<never>()
116-
expectTypeOf(result_eip4844.maxFeePerBlobGas).toEqualTypeOf<bigint>()
116+
expectTypeOf(result_eip4844.maxFeePerBlobGas).toEqualTypeOf<
117+
bigint | undefined
118+
>()
117119
expectTypeOf(result_eip4844.maxFeePerGas).toEqualTypeOf<bigint>()
118120
expectTypeOf(result_eip4844.maxPriorityFeePerGas).toEqualTypeOf<bigint>()
119121

@@ -136,7 +138,9 @@ test('args: type', async () => {
136138
readonly BlobSidecar<`0x${string}`>[]
137139
>()
138140
expectTypeOf(result_eip4844_2.gasPrice).toEqualTypeOf<never>()
139-
expectTypeOf(result_eip4844_2.maxFeePerBlobGas).toEqualTypeOf<bigint>()
141+
expectTypeOf(result_eip4844_2.maxFeePerBlobGas).toEqualTypeOf<
142+
bigint | undefined
143+
>()
140144
expectTypeOf(result_eip4844_2.maxFeePerGas).toEqualTypeOf<bigint>()
141145
expectTypeOf(result_eip4844_2.maxPriorityFeePerGas).toEqualTypeOf<bigint>()
142146
})
@@ -173,7 +177,7 @@ test('args: eip4844 attributes', async () => {
173177
expectTypeOf(result_1.gasPrice).toEqualTypeOf<never>()
174178
expectTypeOf(result_1.maxFeePerGas).toEqualTypeOf<bigint>()
175179
expectTypeOf(result_1.maxPriorityFeePerGas).toEqualTypeOf<bigint>()
176-
expectTypeOf(result_1.maxFeePerBlobGas).toEqualTypeOf<bigint>()
180+
expectTypeOf(result_1.maxFeePerBlobGas).toEqualTypeOf<bigint | undefined>()
177181

178182
const result_2 = await prepareTransactionRequest(client, {
179183
blobs: ['0x'],
@@ -183,13 +187,13 @@ test('args: eip4844 attributes', async () => {
183187
})
184188
expectTypeOf(result_2.type).toEqualTypeOf<'eip4844'>()
185189
expectTypeOf(result_2.blobs).toEqualTypeOf<
186-
readonly Hex[] | readonly ByteArray[]
190+
readonly Hex[] | readonly ByteArray[] | undefined
187191
>()
188192
expectTypeOf(result_2.blobVersionedHashes).toEqualTypeOf<readonly Hex[]>()
189193
expectTypeOf(result_2.gasPrice).toEqualTypeOf<never>()
190194
expectTypeOf(result_2.maxFeePerGas).toEqualTypeOf<bigint>()
191195
expectTypeOf(result_2.maxPriorityFeePerGas).toEqualTypeOf<bigint>()
192-
expectTypeOf(result_2.maxFeePerBlobGas).toEqualTypeOf<bigint>()
196+
expectTypeOf(result_2.maxFeePerBlobGas).toEqualTypeOf<bigint | undefined>()
193197
})
194198

195199
test('args: parameters', async () => {

src/actions/wallet/sendTransaction.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -219,25 +219,28 @@ export async function sendTransaction<
219219
const chainFormat = client.chain?.formatters?.transactionRequest?.format
220220
const format = chainFormat || formatTransactionRequest
221221

222-
const request = format({
223-
// Pick out extra data that might exist on the chain's transaction request type.
224-
...extract(rest, { format: chainFormat }),
225-
accessList,
226-
authorizationList,
227-
blobs,
228-
chainId,
229-
data,
230-
from: account?.address,
231-
gas,
232-
gasPrice,
233-
maxFeePerBlobGas,
234-
maxFeePerGas,
235-
maxPriorityFeePerGas,
236-
nonce,
237-
to,
238-
type,
239-
value,
240-
} as TransactionRequest)
222+
const request = format(
223+
{
224+
// Pick out extra data that might exist on the chain's transaction request type.
225+
...extract(rest, { format: chainFormat }),
226+
accessList,
227+
authorizationList,
228+
blobs,
229+
chainId,
230+
data,
231+
from: account?.address,
232+
gas,
233+
gasPrice,
234+
maxFeePerBlobGas,
235+
maxFeePerGas,
236+
maxPriorityFeePerGas,
237+
nonce,
238+
to,
239+
type,
240+
value,
241+
} as TransactionRequest,
242+
'sendTransaction',
243+
)
241244

242245
const isWalletNamespaceSupported = supportsWalletNamespace.get(client.uid)
243246
const method = isWalletNamespaceSupported

0 commit comments

Comments
 (0)