eth_getTransactionCount | BNB Chain

BNB API method that returns the number of transactions sent from an address at the selected block. This value is also called nonce; it is an important piece of information, especially to ensure that a transaction is not sent twice.

๐Ÿ‘

Get you own node endpoint today

Start for free and get your app to production levels immediately. No credit card required.

You can sign up with your GitHub, X, Google, or Microsoft account.

Parameters

  • addressโ€” the address to retrieve the transaction count.

  • quantity or tag โ€” the integer of a block encoded as hexadecimal or the string with:

    • latest โ€” the most recent block in the blockchain and the current state of the blockchain at the most recent block. A chain reorganization is to be expected.

    • safe โ€” the block that received justification from the beacon chain. Although this block could be involved in a chain reorganization, it would necessitate either a coordinated attack by the majority of validators or an instance of severe propagation latency.

    • finalized โ€” the block accepted as canonical by more than 2/3 of the validators. A chain reorganization is extremely unlikely, and it would require at least 1/3 of the staked ETH to be burned.

    • earliest โ€” the earliest available or genesis block.

    • pending โ€” the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.

      ๐Ÿ“˜

      See the default block parameter and How The Merge Impacts Ethereumโ€™s Application Layer.

Response

  • quantity โ€” an integer value identifying the number of transactions sent from an address at the specified block.

eth_getTransactionCount code examples

const { Web3 } = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);

async function getTransactionsCount(address, blockId) {
  const count = await web3.eth.getTransactionCount(address, blockId)
  console.log(count);
}

getTransactionsCount("0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9", 'latest')
const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);

const getNonce = async (address, blockId) => {
    const nonce = await provider.send("eth_getTransactionCount", [address, blockId]);
    console.log(nonce);
  };

  getNonce("0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9", "latest")
from web3 import Web3  
node_url = "CHAINSTACK_NODE_URL" 

web3 = Web3(Web3.HTTPProvider(node_url)) 
print(web3.eth.get_transaction_count("0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9", "latest")) 

Use case

One of the most common use cases for eth_getTransactionCountis to create the transaction object built in a script designed to send a transaction. The nonce field is required, and it is retrieved using the eth_getTransactionCount method.

Use the eth_getTransactionCount RPC method yourself

Language
Click Try It! to start a request and see the response here!