getNonce method

Future<BigInt> getNonce(
  1. EthereumAddress address
)

Returns the next available transaction nonce for the given Ethereum address.

This method queries the network via Web3Client.getTransactionCount with a block tag of pending, ensuring the returned nonce reflects both mined and in-mempool transactions. This is the recommended behavior for constructing new EIP-1559 or EIP-7702 transactions.

Example:

final nonce = await getNonce(myAddress);
print('Next nonce: $nonce');

Implementation

Future<BigInt> getNonce(EthereumAddress address) async {
  final nonce = await ctx.web3Client.getTransactionCount(
    address,
    atBlock: const BlockNum.pending(),
  );
  return BigInt.from(nonce);
}