Skip to main content
POST
/
0a9d79d93fb2f4a4b1e04695da2b77a7
eth_getTransactionCount
curl --request POST \
  --url https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7 \
  --header 'Content-Type: application/json' \
  --data '
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_getTransactionCount",
  "params": [
    "0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990",
    "latest"
  ]
}
'
import requests

url = "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"

payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": ["0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990", "latest"]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'eth_getTransactionCount',
params: ['0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990', 'latest']
})
};

fetch('https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'eth_getTransactionCount',
'params' => [
'0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990',
'latest'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"

payload := strings.NewReader("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getTransactionCount\",\n \"params\": [\n \"0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990\",\n \"latest\"\n ]\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7")
.header("Content-Type", "application/json")
.body("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getTransactionCount\",\n \"params\": [\n \"0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990\",\n \"latest\"\n ]\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getTransactionCount\",\n \"params\": [\n \"0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990\",\n \"latest\"\n ]\n}"

response = http.request(request)
puts response.read_body
{
  "jsonrpc": "<string>",
  "id": 123,
  "result": {}
}
Ethereum 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.
When called against a block older than the latest ~128 blocks, this method is treated as an archive request (2 RUs instead of 1 RU). See request units.
Get your own node endpoint todayStart 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.

Response

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

eth_getTransactionCount code examples

Learn more about the ChainstackProvider in ethers.js: ethers ChainstackProvider Documentation.
const ethers = require("ethers");

// Create a ChainstackProvider instance for Ethereum mainnet
const chainstack = new ethers.ChainstackProvider("mainnet");

const getNonce = async (address, blockId) => {
  const nonce = await chainstack.send("eth_getTransactionCount", [ // This value is returned in HEX
    address,
    blockId,
  ]);

  // Convert hex to decimal
  const nonceDecimal = parseInt(nonce, 16);

  console.log(nonceDecimal);
};

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

web3 = Web3(Web3.HTTPProvider(node_url)) 
print(web3.eth.get_transaction_count("0xCb6Ed7E78d27FDff28127F9CbD61d861F09a2324", "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. The following code shows how to build and send a transaction using ethers.js.
Security noticeYou need your private key to sign the transaction; never share your private key with anyone.On a side note, the private key in this case must be imported with ‘0x’ at the beginning of the string.
index.js
const ethers = require("ethers");

// Create a ChainstackProvider instance for Ethereum mainnet
const chainstack = new ethers.ChainstackProvider("mainnet");

// Function to get the transaction count (nonce)
async function getTransactionsCount(address) {
    return await chainstack.getTransactionCount(address, "latest");
}

// Function to perform the transaction
async function sendEther() {
    try {
        // Add your private key here (ideally from an environment variable)
        const privateKey = "0xPRIVATE_KEY";

        // Create a wallet connected to the provider
        const wallet = new ethers.Wallet(privateKey, chainstack);

        // Retrieve the nonce for the sender's address
        const nonce = await getTransactionsCount(wallet.address);

        // Transaction parameters
        const toAddress = "0xae2Fc483527B8EF99EB5D9B44875F005ba1FaE13"; // Replace with the receiver's address
        const value = ethers.parseEther("1"); // Amount in ETH (e.g., 1 ETH)

        console.log(`Sending ${ethers.formatEther(value)} ETH from ${wallet.address} to ${toAddress}...`)

        // Send the transaction
        const txResponse = await wallet.sendTransaction({
            to: toAddress,
            value: value,
            nonce: nonce,  // Include the nonce
            // Optional: Specify gasLimit and fee fields if needed
        });

        // Wait for the transaction to be mined and get the receipt
        const receipt = await txResponse.wait();

        console.log("Transaction receipt:", receipt);
    } catch (error) {
        console.error("Transaction failed:", error);
    }
}

// Execute the function
sendEther();
The code sets up a direct transaction to be broadcast to the Ethereum network using ethers.js. Initially, the script establishes a connection to an Ethereum node and sets up the provider instance. The key part of the transaction process involves retrieving the nonce for the sender’s address, which is done through the getTransactionsCount function. This function calls provider.getTransactionCount, passing the sender’s address and returning the count of transactions previously sent from this address. This count, used as the nonce, is critical for ensuring the transaction’s uniqueness and order in the blockchain. After setting up the sender’s wallet with a private key, the script defines the transaction parameters, including the toAddress and the value (amount of ETH to be transferred). The value is defined in wei using ethers.parseEther and then formatted back to ETH with ethers.formatEther for logging purposes. The script then constructs a transaction object that includes essential fields such as to, value, and nonce. While gasLimit and the fee fields can be specified, they are optional in this script, as ethers.js will estimate and populate default values if they are not explicitly set. The transaction is sent using wallet.sendTransaction, which handles the transaction signing under the hood with the private key from the wallet. This approach simplifies the transaction creation and sending process, as the complex steps of manually creating, signing, and serializing the transaction are abstracted away by ethers.js. This will ultimately send a transaction using the eth_sendRawTransaction method. Once the transaction is sent, a receipt is obtained and logged, providing details of the executed transaction. In case of any errors during the transaction process, these are caught and logged, aiding in troubleshooting and ensuring robust error handling. The sendEther function encapsulates the entire process, and its execution triggers the sending of the transaction, demonstrating a streamlined and efficient way to handle Ethereum transactions programmatically.

Body

application/json
id
integer
default:1
jsonrpc
string
default:2.0
method
string
default:eth_getTransactionCount
params
string[]

The address to check

Response

200 - application/json

The address nonce

jsonrpc
string
id
integer
result
object
Last modified on July 7, 2026