Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/keyed-nonce-rpc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"ox": patch
---

Added optional `nonceKeys` to `eth_getTransactionCount` requests.

```ts
const nonce = await provider.request({
method: 'eth_getTransactionCount',
params: [address, 'pending', ['0x1', '0x2']],
})
```
32 changes: 31 additions & 1 deletion src/core/_test/RpcSchema.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RpcSchema } from 'ox'
import { expectTypeOf, test } from 'vitest'
import { describe, expectTypeOf, test } from 'vitest'

test('ToViem: converts ox schema to viem schema', () => {
type OxSchema =
Expand Down Expand Up @@ -161,3 +161,33 @@ test('frame simulation results expose payer and frame results', () => {
expectTypeOf<Frame['stateGasUsed']>().toEqualTypeOf<`0x${string}`>()
expectTypeOf<Frame['returnData']>().toEqualTypeOf<`0x${string}`>()
})

describe('Eth', () => {
test('eth_getTransactionCount', () => {
type Request = RpcSchema.ExtractRequest<
RpcSchema.Eth,
'eth_getTransactionCount'
>
type Params = Request['params']

expectTypeOf<['0x1234', 'latest']>().toMatchTypeOf<Params>()
expectTypeOf<
['0x1234', 'pending', readonly ['0x0']]
>().toMatchTypeOf<Params>()
expectTypeOf<
['0x1234', '0x10', readonly ['0x1', '0x2']]
>().toMatchTypeOf<Params>()
expectTypeOf<['0x1234', 'latest', undefined]>().toMatchTypeOf<Params>()
expectTypeOf<['0x1234', 'latest', '0x1']>().not.toMatchTypeOf<Params>()
expectTypeOf<
['0x1234', 'latest', readonly [1n]]
>().not.toMatchTypeOf<Params>()
expectTypeOf<['0x1234', readonly ['0x1']]>().not.toMatchTypeOf<Params>()
expectTypeOf<
['0x1234', 'latest', readonly ['0x1'], '0x2']
>().not.toMatchTypeOf<Params>()
expectTypeOf<
RpcSchema.ExtractReturnType<RpcSchema.Eth, 'eth_getTransactionCount'>
>().toEqualTypeOf<`0x${string}`>()
})
})
11 changes: 10 additions & 1 deletion src/core/internal/rpcSchemas/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,15 @@ export type Eth = RpcSchema.From<
ReturnType: Transaction.Rpc | null
}
/**
* Returns the number of transactions sent from an address
* Returns the account nonce or the shared EIP-8250 sequence at the selected block.
*
* Omitted `nonceKeys` or `['0x0']` queries the account nonce. Nonzero keys query
* their shared sequence, with unused keys returning zero. `pending` uses pending state.
* Keys must be 1–16 canonical uint256 quantities in strictly increasing order;
* zero cannot be combined with other keys.
*
* Invalid keys return RPC error `-32602`. Differing sequences or EIP-8250 being
* inactive at the selected block for nonzero keys return `-32000`.
*
* @example
* ```
Expand All @@ -575,6 +583,7 @@ export type Eth = RpcSchema.From<
| Block.Tag
| Block.Hash
| Block.Identifier,
nonceKeys?: readonly Hex.Hex[] | undefined,
]
}
ReturnType: Hex.Hex
Expand Down
Loading