eth_getTransactionCount - Monad

This method returns the number of transactions sent from an address (the nonce).

Parameters

ParameterTypeRequiredDescription
addressstringYesThe address to get the transaction count for.
blockNumberstringNoBlock number in hex, or "latest", "earliest", "pending", "safe", "finalized".

Request

curl

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionCount",
    "params": ["0x727752abbf7a9ef2f3c15e322dd43bf642d26eb7", "latest"],
    "id": "getblock.io"
}'

axios.js

javascriptimport axios from 'axios';

const data = JSON.stringify({
    "jsonrpc": "2.0",
    "method": "eth_getTransactionCount",
    "params": ["0x727752abbf7a9ef2f3c15e322dd43bf642d26eb7", "latest"],
    "id": "getblock.io"
});

const config = {
    method: 'post',
    url: 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers: {
        'Content-Type': 'application/json'
    },
    data: data
};

axios(config)
    .then(response => console.log(JSON.stringify(response.data)))
    .catch(error => console.log(error));

request.py

pythonimport requests
import json

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"

payload = json.dumps({
    "jsonrpc": "2.0",
    "method": "eth_getTransactionCount",
    "params": ["0x727752abbf7a9ef2f3c15e322dd43bf642d26eb7", "latest"],
    "id": "getblock.io"
})

headers = {
    'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers, data=payload)
print(response.text)

main.rs

rustuse reqwest::header;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header(header::CONTENT_TYPE, "application/json")
        .body(r#"{
            "jsonrpc": "2.0",
            "method": "eth_getTransactionCount",
            "params": ["0x727752abbf7a9ef2f3c15e322dd43bf642d26eb7", "latest"],
            "id": "getblock.io"
        }"#)
        .send()
        .await?;
    
    println!("{}", response.text().await?);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x1a"
}

Response Parameters

FieldTypeDescription
resultstringThe number of transactions sent from the address in hexadecimal.

Use Case

The eth_getTransactionCount method is essential for:

  • Getting the correct nonce for new transactions
  • Transaction building and signing
  • Detecting pending transactions
  • Wallet transaction management
  • High-frequency trading nonce management
  • Account activity analysis

Error Handling

Status CodeError MessageCause
403ForbiddenMissing or invalid ACCESS-TOKEN.
-32602Invalid paramsInvalid address format.
-32000Resource not foundBlock not found.
-32601Failed to parse requestsyntax error

Web3 Integration

ethers.js

javascriptimport { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

// Get confirmed nonce
const nonce = await provider.getTransactionCount("0x727752abbf7a9ef2f3c15e322dd43bf642d26eb7");
console.log('Confirmed nonce:', nonce);

// Get pending nonce (includes pending transactions)
const pendingNonce = await provider.getTransactionCount(address, 'pending');
console.log('Pending nonce:', pendingNonce);

viem

javascriptimport { createPublicClient, http } from "viem";
import { monad } from "viem/chains";
/ Create Viem client with GetBlock
onst client = createPublicClient({
 chain: monad,
 transport: http(
   import.meta.env.MONAD_ACCESS_TOKEN
 ),
);
/ Using the method through Viem
sync function Call() {
 try {
   // Method-specific Viem implementation
   const result = await client.request({
     method: "eth_getTransactionCount",
     params: ["0x727752abbf7a9ef2f3c15e322dd43bf642d26eb7", "latest"],
   });
   console.log("Result:", result);
   return result;
 } catch (error) {
   console.error("Viem Error:", error);
   throw error;
 }
}