Web3

Full Tutorial: How to Get Wallet Transactions Using RPC Nodes

Are you on the lookout for a simple means to get pockets transactions utilizing RPC nodes? If that’s the case, you’re in the correct place. In at this time’s tutorial, we’ll discover Moralis’ Prolonged RPC Strategies and our eth_getTransactions endpoint, which permits you to fetch any pockets’s native transaction historical past with only one name. Keen to be taught the way it works? Take a look at the strategy in motion right here:

import fetch from 'node-fetch';

const choices = {
 methodology: 'POST',
 headers: {
   settle for: 'utility/json',
   'content-type': 'utility/json'
 },
 physique: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getTransactions",
   "params": [
     {
       "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
       "limit": 100,
     }
   ]
 })
};

fetch('YOUR_NODE_URL', choices)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

By working the script above, you’ll obtain the native transaction historical past of the desired pockets, enriched with timestamps, gasoline costs, deal with labels, and extra. Right here’s a pattern response:

{
  //...
    consequence: [
      {
        hash: '0xd89b02f289a08ae7b2feead06031fec20777bad8b73fc8d853f9040bc423a6c7',
        nonce: '0',
        transaction_index: '142',
        from_address: '0xda74ac6b69ff4f1b6796cddf61fbdd4a5f68525f',
        from_address_label: '',
        to_address: '0xdac17f958d2ee523a2206206994597c13d831ec7',
        to_address_label: 'Tether USD (USDT)',
        value: '0',
        gas: '207128',
        gas_price: '17020913648',
        input: '0xa9059cbb00000000000000000000000028c6c06298d514db089934071355e5743bf21d6000000000000000000000000000000000000000000000000000000017a1df1700',
        receipt_cumulative_gas_used: '8270587',
        receipt_gas_used: '41309',
        receipt_contract_address: null,
        receipt_root: null,
        receipt_status: '1',
        block_timestamp: '2023-01-22T15:00:11.000Z',
        block_number: '16463098',
        block_hash: '0x2439330d0a282f9a6464b0aceb9f766ac4d7b050c048b4a1322b48544c61e01d',
        transaction_fee: '0.000703116921885232'
    	},
      //...
    ]
  }
}

That’s it! It’s straightforward to retrieve pockets transactions utilizing RPC nodes when working with Moralis. Nevertheless, for a extra detailed tutorial, be a part of us on this article or try the Moralis YouTube video beneath:

Need to get pockets transactions utilizing RPC nodes your self? Join free with Moralis to instantly entry all our Prolonged RPC Strategies!

Overview

If you happen to’re trying to construct decentralized functions (dapps), whether or not it’s a cryptocurrency pockets, portfolio tracker, tax platform, or related tasks, you’ll seemingly want entry to your customers’ native transaction historical past. Nevertheless, should you’re planning on getting this data utilizing RPC nodes, it’s simpler stated than performed, because it requires a number of requests and intensive guide knowledge aggregation. Happily, there’s now a greater means: Moralis’ Prolonged RPC Strategies. 

With our Prolonged RPC Strategies, you may question the identical decoded knowledge that our APIs present, however by way of RPC-style requests. A single name permits you to retrieve a pockets’s native transaction historical past, token costs, token balances, and way more.

However how does this work? If you happen to’d like to be taught extra about our Prolonged RPC Strategies, be a part of us on this tutorial. Let’s dive straight in! 

Introducing Moralis’ Subsequent-Technology RPC Nodes – The Best Approach to Get Wallet Transactions

Moralis is the trade’s main supplier of next-generation RPC nodes. With our intuitive person interface, you may entry nodes for all main chains with only a click on. As such, it doesn’t matter what community you’re constructing on, we’ve bought you coated.

Moralis RPC nodes.

However what makes our nodes distinctive?

  • Pace: Our RPC nodes set the benchmark for pace, with response occasions as little as 70 ms.
  • Reliability: With 99.9% uptime, you may belief our node infrastructure.
  • Prolonged RPC Strategies: Moralis’ Prolonged RPC Strategies improve our node providing, permitting you to question decoded, human-readable knowledge through RPC-style requests.

Now, let’s dive a bit deeper into our Prolonged RPC Strategies, which allow you to seamlessly get pockets transactions utilizing RPC nodes! 

Prolonged RPC Strategies

Moralis’ Prolonged RPC Strategies make fetching decoded, human-readable knowledge with RPC nodes a breeze. With only one name, you may effortlessly get pockets transactions, NFTs, token costs, metadata, and way more. As such, when utilizing Moralis and our Prolonged RPC Strategies, you may considerably streamline your developer expertise. 

Text: "Extended RPC Methods"

What knowledge are you able to fetch with our Prolonged RPC Strategies?

  • eth_getTransactions: Get the native transactions of a pockets. 
  • eth_getDecodedTransactions: Question the complete transaction historical past of a pockets. 
  • eth_getTokenBalances: Retrieve the ERC-20 balances of a pockets. 
  • eth_getTokenMetadata: Get the metadata of any ERC-20 token.
  • eth_getTokenPrice: Entry the worth of any ERC-20 token.
  • eth_getNFTBalances: Get the NFT balances of any pockets.
  • eth_getNFTCollections: Fetch the NFT collections held by a pockets. 

In abstract, with our Prolonged RPC Strategies, you may seamlessly fetch the identical decoded, human-readable knowledge our APIs present, however by way of RPC-style requests.

eth_getTransactions – Get Wallet Transactions Using RPC Nodes with One Request

With the eth_getTransactions methodology, now you can seamlessly get any pockets’s native transaction historical past with only one single RPC request. Every transaction can also be totally enriched with further knowledge, together with time stamps, gasoline costs, deal with labels, and way more. As such, when utilizing the eth_getTransactions endpoint, you get decoded knowledge out of the field with only one name. 

Wallet connected with RPC nodes.

However how does this work? And what does an precise response appear to be? If you happen to’re on the lookout for the solutions to these questions, be a part of us within the subsequent part, the place we present you precisely how to get pockets transactions utilizing RPC nodes in three easy steps. 

Tutorial: How to Get Wallet Transactions Using RPC Nodes

With our Prolonged RPC Strategies and the eth_getTransactions endpoint, you may get pockets transactions utilizing RPC nodes in three easy steps: 

  1. Enroll with Moralis & get a node URL.
  2. Write a script calling eth_getTransactions
  3. Run the code. 

However earlier than we will dive into the tutorial, you want to cope with a number of stipulations. 

Stipulations

Be sure to have the next prepared earlier than persevering with:

Step 1: Signal Up with Moralis & Get a Node URL

Click on the ”Begin for Free” button on the prime proper and join with Moralis: 

Arrow pointing at "Start for Free" button on Moralis website.

Log in, navigate to the ”Nodes” tab, and click on ”+ Create Node”: 

Red arrow pointing at "Nodes" tab and "+ Create Node" button

Select ”Ethereum,” then ”Mainnet,” and click on ”Create Node”: 

Highlighting configurations for Ethereum node.

Copy and save one in all your node URLs, as you’ll want it within the subsequent step: 

Arrows pointing at copy button for RPC nodes.

Step 2: Write a Script Calling eth_getTransactions

Launch your IDE, arrange a folder, open a brand new terminal, and initialize a venture with this command:

npm init

Set up the required dependencies with the next command: 

npm set up node-fetch --save
npm set up moralis @moralisweb3/common-evm-utils

Open your ”bundle.json” file and add ”sort”: ”module” to the checklist: 

"type": "module" highlighted in code editor.

Create an ”index.js” file and add the code beneath: 

import fetch from 'node-fetch';

const choices = {
 methodology: 'POST',
 headers: {
   settle for: 'utility/json',
   'content-type': 'utility/json'
 },
 physique: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getTransactions",
   "params": [
     {
       "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
       "limit": 100,
     }
   ]
 })
};

fetch('YOUR_NODE_URL', choices)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

Subsequent, you want to alter the code barely. Exchange YOUR_NODE_URL with the node URL you copied throughout step one. Additionally, configure the deal with parameter in order that it matches your request: 

Arrows pointing at YOUR_NODE_URL and address in code editor.

Step 3: Run the Code

Open a brand new terminal and run this command in your venture’s root folder: 

node index.js

In return, you’ll get an inventory of the pockets’s previous native transactions, enriched with timestamps, gasoline costs, deal with labels, and way more knowledge for every occasion. Right here’s a pattern response: 

{
  //...
    consequence: [
      {
        hash: '0xd89b02f289a08ae7b2feead06031fec20777bad8b73fc8d853f9040bc423a6c7',
        nonce: '0',
        transaction_index: '142',
        from_address: '0xda74ac6b69ff4f1b6796cddf61fbdd4a5f68525f',
        from_address_label: '',
        to_address: '0xdac17f958d2ee523a2206206994597c13d831ec7',
        to_address_label: 'Tether USD (USDT)',
        value: '0',
        gas: '207128',
        gas_price: '17020913648',
        input: '0xa9059cbb00000000000000000000000028c6c06298d514db089934071355e5743bf21d6000000000000000000000000000000000000000000000000000000017a1df1700',
        receipt_cumulative_gas_used: '8270587',
        receipt_gas_used: '41309',
        receipt_contract_address: null,
        receipt_root: null,
        receipt_status: '1',
        block_timestamp: '2023-01-22T15:00:11.000Z',
        block_number: '16463098',
        block_hash: '0x2439330d0a282f9a6464b0aceb9f766ac4d7b050c048b4a1322b48544c61e01d',
        transaction_fee: '0.000703116921885232'
    	},
      //...
    ]
  }
}

That’s it; it’s straightforward to get pockets transactions utilizing RPC nodes when working with Moralis! 

To be taught extra about this, try the official eth_getTransactions documentation web page.

Use Instances for Wallet Transaction Information

Now that you know the way to seamlessly get pockets transactions utilizing RPC nodes, let’s discover some distinguished use instances for this knowledge. Listed here are three key examples:

  • Cryptocurrency Wallets: Wallets require entry to transactions to show previous transfers, offering customers with a transparent overview of their historic exercise.
  • Portfolio Trackers: Portfolio trackers should entry previous transfers to precisely monitor the efficiency of customers’ property.
  • Tax Platforms: Tax platforms want a complete overview of customers’ previous buying and selling actions to generate correct tax reviews.
Wallet surrounded by tokens.

Be aware that these are just some examples – pockets transaction knowledge is essential for many dapps!

Past How to Get Wallet Transactions Using RPC Nodes – Diving Deeper Into Moralis’ Prolonged RPC Strategies

Now that you know the way to get pockets transactions utilizing RPC nodes, we’ll dive a bit deeper into our different Prolonged RPC Strategies. Extra particularly, we’ll discover the next three: 

  • eth_getTokenBalances
  • eth_getDecodedTransactions
  • eth_getTokenPrice

So, let’s kick issues off with eth_getTokenBalances

eth_getTokenBalances

With our eth_getTokenBalances methodology, you may seamlessly get ERC-20 token balances utilizing RPC nodes. As an alternative of getting to make a number of RPC requests and stitching collectively knowledge by yourself, you solely want a single name. Right here’s the strategy in motion:

import fetch from 'node-fetch';

const choices = {
 methodology: 'POST',
 headers: {
   settle for: 'utility/json',
   'content-type': 'utility/json'
 },
 physique: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getTokenBalances",
   "params": [
     {
       "address": "0xcB1C1FdE09f811B294172696404e88E658659905",
     }
   ]
 })
};

fetch('YOUR_NODE_URL', choices)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In response to calling the eth_getTokenBalances methodology, you’ll obtain the ERC-20 token balances of the desired pockets. What’s extra, all tokens are enriched with logos, decimals, thumbnails, spam indicators, and way more. Right here’s a pattern response:

{
  //...
  consequence: [
    {
      token_address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
      name: 'Wrapped Ether',
      symbol: 'WETH',
      decimals: 18,
      logo: '
      thumbnail: '
      balance: '10000000000000000',
      possible_spam: false,
      verified_contract: true,
      total_supply: '2746607222348759943423350',
      total_supply_formatted: '2746607.22234875994342335',
      percentage_relative_to_total_supply: 3.64085549569e-7
    },
    //...
  ]
}

eth_getDecodedTransactions

With the eth_getDecodedTransactions methodology, you may effortlessly get decoded pockets historical past utilizing an RPC node. No want to make a number of requests, combination knowledge your self, or decode data. When utilizing Moralis, you get all the information you want with only one name. Right here’s an instance of how to name the eth_getDecodedTransactions endpoint:

import fetch from 'node-fetch';

const choices = {
 methodology: 'POST',
 headers: {
   settle for: 'utility/json',
   'content-type': 'utility/json'
 },
 physique: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getDecodedTransactions",
   "params": [
     {
       "address": "0xda74Ac6b69Ff4f1B6796cdDf61fBDd4A5f68525f",
     }
   ]
 })
};

fetch('YOUR_NODE_URL', choices)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In response to calling eth_getDecodedTransactions, you’ll obtain the desired pockets’s full historical past, enriched with computerized class tags, occasion summaries, deal with labels, and extra. Right here’s an instance of what the response may appear to be:

{
  //...
    "result": [
      {
        "block_hash": "0x660274d577cd20b0b82c1bff5f3c5641ba6027544e005f9256d5add9c7447920",
        "block_number": "19868695",
        "block_timestamp": "2024-05-14T14:00:23.000Z",
        "from_address": "0xda74ac6b69ff4f1b6796cddf61fbdd4a5f68525f",
        "from_address_label": null,
        "from_address_entity": null,
        "from_address_entity_logo": null,
        "to_address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
        "to_address_label": "Tether USD (USDT)",
        "to_address_entity": null,
        "to_address_entity_logo": null,
        "gas": "55331",
        "gas_price": "13623172301",
        "hash": "0xc565260238f59fc3f35b74f3011375c7d637db9b075f77d342c30d19f946272e",
        "nonce": "14",
        "receipt_cumulative_gas_used": "13917979",
        "receipt_gas_used": "41309",
        "receipt_status": "1",
        "transaction_fee": "0.000562759624582009",
        "transaction_index": "75",
        "value": "0",
        "receipt_contract_address": null,
        "nft_transfers": [],
        "erc20_transfers": [
          {
            "token_name": "Tether USD",
            "token_symbol": "USDT",
            "token_logo": "
            "token_decimals": "6",
            "from_address": "0xda74ac6b69ff4f1b6796cddf61fbdd4a5f68525f",
            "from_address_entity": null,
            "from_address_entity_logo": null,
            "from_address_label": null,
            "to_address": "0x28c6c06298d514db089934071355e5743bf21d60",
            "to_address_label": "Binance 14",
            "to_address_entity": "Binance",
            "to_address_entity_logo": "
            "address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
            "log_index": 338,
            "value": "50000000000",
            "possible_spam": false,
            "verified_contract": true,
            "direction": "send",
            "value_formatted": "50000"
          }
        ],
        "method_label": "transfer",
        "native_transfers": [],
        "summary": "Sent 50,000 USDT to Binance 14",
        "possible_spam": false,
        "category": "token send"
      },
      //...
    }
  ]
}

eth_getTokenPrice

The eth_getTokenPrice methodology permits you to seamlessly retrieve the worth of any token utilizing RPC-style requests. This eliminates the necessity to contain third-party API suppliers when integrating worth knowledge into your dapps. Right here’s the eth_getTokenPrice methodology in motion:

import fetch from 'node-fetch';

const choices = {
 methodology: 'POST',
 headers: {
   settle for: 'utility/json',
   'content-type': 'utility/json'
 },
 physique: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getTokenPrice",
   "params": [
     {
       "address": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
       "include": "percent_change"
     }
   ]
 })
};

fetch(‘YOUR_NODE_URL’, choices)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In response to working the script above, you’ll obtain the USD and native worth of the desired token. Moreover, the response is enriched with token logos, worth modifications over time, spam indicators, and extra. Right here’s what it’d appear to be:

{
  //...
  consequence: {
    tokenName: 'Tether USD',
    tokenSymbol: 'USDT',
    tokenLogo: '
    tokenDecimals: '6',
    nativePrice: {
      worth: '375760131462618',
      decimals: 18,
      identify: 'Ether',
      image: 'ETH',
      deal with: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
    },
    usdPrice: 1.0000402502911871,
    usdPriceFormatted: '1.000040250291187229',
    '24hrPercentChange': '-0.04543241491797881',
    exchangeName: 'Uniswap v3',
    exchangeAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
    tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
    priceLastChangedAtBlock: '20534105',
    possibleSpam: false,
    verifiedContract: true,
    pairAddress: '0xc7bbec68d12a0d1830360f8ec58fa599ba1b0e9b',
    pairTotalLiquidityUsd: '7148031.13'
  }
}

If you happen to’d like to be taught extra about our different strategies, please try the official Prolonged RPC Strategies documentation web page.

Exploring Moralis’ Web3 APIs

Moralis is Web3’s main knowledge supplier, and as well as to next-generation RPC nodes, we additionally provide a complete suite of Web3 APIs. Some distinguished examples right here included the Wallet API, Token API, Streams API, and lots of extra. As such, when leveraging Moralis, you get all crypto knowledge in a single place.

Moralis logo.

What makes our APIs particular? 

  • Complete: Our APIs present the trade’s most complete responses, providing you with extra knowledge with fewer calls. Get token balances, any pockets’s transaction historical past, NFT costs, and way more with single requests. 
  • Cross-Chain: Moralis’ Web3 APIs are cross-chain suitable, offering full characteristic parity throughout all main chains, together with Ethereum, BSC, Optimism, Base, and lots of extra. 
  • Safe: Moralis holds a SOC 2 Kind 2 certification, demonstrating our dedication to safety and reliability. 

Now, let’s dive a bit deeper into our Web3 API suite by exploring a few of our distinguished interfaces! 

Moralis’ Web3 API Suite

In our suite of Web3 APIs, you’ll discover a number of interfaces tailor-made for varied use instances. Listed here are 5 distinguished examples: 

  • Wallet API: Get any pockets’s full historical past, token balances with costs, web value, profitability, and way more with single requests. That is the proper instrument for anybody trying to construct Web3 wallets or combine pockets performance into dapps. 
  • Token API: Fetch token balances with costs, metadata, transactions, and way more with ease. That is your go-to answer for ERC-20 knowledge, serving to you construct every thing from portfolio trackers to DEXs. 
  • NFT API: Question NFT balances, costs, up-to-date metadata, transactions, and way more utilizing single strains of code. This instrument is superb for anybody trying to construct NFT marketplaces, Web3 video games, or different related platforms. 
  • Worth API: Get real-time and historic costs for each NFTs and ERC-20 tokens. The Worth API is the last word instrument should you’re trying to combine worth knowledge into your dapps. 
  • Streams API: The Streams API is Moralis’ real-time knowledge answer, permitting you to arrange Web3 knowledge pipelines on the click on of a button. That is the most effective API for organising real-time alerts, populating databases with latest on-chain occasions, or just integrating present knowledge into dapps. 

Please try the official Web3 API web page to be taught extra about our interfaces! 

Abstract: How to Get Wallet Transactions Using RPC Nodes

Suppose you need to construct Web3 tasks like portfolio trackers, tax platforms, wallets, or different related dapps. In that case, chances are high that you simply’ll want entry to your customers’ native transaction historical past. Nevertheless, fetching this knowledge utilizing RPC nodes and traditional strategies like eth_getTransactionByHash is kind of difficult, because it requires a number of requests and numerous guide knowledge aggregation. Happily, now you can get this knowledge with only one name when utilizing Moralis’ Prolonged RPC Strategies.

Wallet transactions with tokens.

With our Prolonged RPC Strategies, you may get decoded, human-readable knowledge by way of RPC-style requests. Get pockets transactions, decoded pockets historical past, token balances, costs, and way more with single calls. 

As an example, that is how straightforward it’s to get pockets transactions utilizing RPC nodes when constructing with Moralis: 

import fetch from 'node-fetch';

const choices = {
 methodology: 'POST',
 headers: {
   settle for: 'utility/json',
   'content-type': 'utility/json'
 },
 physique: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getTransactions",
   "params": [
     {
       "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
       "limit": 100,
     }
   ]
 })
};

fetch('YOUR_NODE_URL', choices)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In return for calling the script above, you get the native transaction historical past of the desired pockets, enriched with timestamps, gasoline costs, deal with labels, and extra. Right here’s a pattern response: 

{
  //...
    consequence: [
      {
        hash: '0xd89b02f289a08ae7b2feead06031fec20777bad8b73fc8d853f9040bc423a6c7',
        nonce: '0',
        transaction_index: '142',
        from_address: '0xda74ac6b69ff4f1b6796cddf61fbdd4a5f68525f',
        from_address_label: '',
        to_address: '0xdac17f958d2ee523a2206206994597c13d831ec7',
        to_address_label: 'Tether USD (USDT)',
        value: '0',
        gas: '207128',
        gas_price: '17020913648',
        input: '0xa9059cbb00000000000000000000000028c6c06298d514db089934071355e5743bf21d6000000000000000000000000000000000000000000000000000000017a1df1700',
        receipt_cumulative_gas_used: '8270587',
        receipt_gas_used: '41309',
        receipt_contract_address: null,
        receipt_root: null,
        receipt_status: '1',
        block_timestamp: '2023-01-22T15:00:11.000Z',
        block_number: '16463098',
        block_hash: '0x2439330d0a282f9a6464b0aceb9f766ac4d7b050c048b4a1322b48544c61e01d',
        transaction_fee: '0.000703116921885232'
    	},
      //...
    ]
  }
}

That’s it! You now know the way to get pockets transactions utilizing RPC nodes! 

If you happen to discovered this tutorial attention-grabbing, take into account testing extra content material on the weblog. As an example, you may find out how to get DeFi protocol knowledge or discover the ins and outs of QuickNode Streams. 

Moreover, if you need to use the Prolonged RPC Strategies your self, don’t overlook to join an account with Moralis. You may create your account at no cost, and also you’ll get prompt entry to all our premier growth instruments! 

DailyBlockchain.News Admin

Our Mission is to bridge the knowledge gap and foster an informed blockchain community by presenting clear, concise, and reliable information every single day. Join us on this exciting journey into the future of finance, technology, and beyond. Whether you’re a blockchain novice or an enthusiast, DailyBlockchain.news is here for you.
Back to top button