getNextNonce
Get the next nonce to be used in the next transaction.
Usage
example.ts
import { publicClient } from "./client";
const nonce = await publicClient.getNextNonce({
address: "cfx:...",
});Returns
number
The next nonce that should be used by the given address.
Parameters
address
- Type:
Address
const nonce = await publicClient.getNextNonce({
address: "cfx:...",
});tryTxPool (optional)
- Type:
boolean - Defaut:
true
Conflux transactions execution will be delayed for several seconds. During this period, the nonce retrieved using cfx_getNextNonce may still reflect an outdated value, while txpool_nextNonce will provide the correct nonce. However, it's important to note that not all RPC nodes support the txpool_nextNonce method.
If you dont want to use the txpool_nextNonce, you can set tryTxPool to false.
const nonce = await publicClient.getNextNonce({
address: "cfx:...",
tryTxPool: true,
});epochTag (optional)
- Type:
latest_state|latest_confirmed|latest_checkpoint|earliest - Defaut:
latest_state
const nonce = await publicClient.getNextNonce({
address: "cfx:...",
epochTag: "latest_state",
});epochNumber (optional)
- Type:
bigint
const nonce = await publicClient.getNextNonce({
address: "cfx:...",
epochNumber: 1n,
});