November 16, 2023

Crypto Wallet History API – Get Users’ Wallet Transaction History

Table of Contents
Crypto Wallet History API - Get Users’ Wallet Transaction History

Are you building a decentralized exchange (DEX), crypto wallet, or any other Web3 platform and need an easy way to query a wallet’s history? If so, you’re precisely where you need to be. In today’s guide, we’ll show you how to fetch the history of any address using the best crypto wallet history API – Moralis’ Wallet API. Thanks to this tool’s accessibility, you only need a single endpoint to get all the data you need! 

Say goodbye to countless API calls and the headache of stitching together internal transfers, ERC-20 transactions, and other events. With just one call, our Wallet History endpoint allows you to construct a comprehensive timeline of a wallet’s history. If you’re eager to jump straight into the code, check out the endpoint in action down below: 

import fetch from 'node-fetch';

const options = {
 method: 'GET',
 headers: {
   accept: 'application/json',
   'X-API-Key': 'YOUR_API_KEY'
 },
};

fetch(
 'https://deep-index.moralis.io/api/v2.2/wallets/0xd8da6bf26964af9d7eed9e03e53415d37aa96045/history?chain=eth&order=DESC',
 options
)
 .then((response) => response.json())
 .then((response) => console.log(response))
 .catch((err) => console.error(err));

In return for running the script above, you get the complete history of the wallet specified in the query parameters, along with address labels, transaction categories, summaries, and much more. Here’s an example of what it might look like:

{
  //...
  "result": [
    {
      "hash": "0xdb50bd448ddc61166989477545fc95c76edcf6febdac5d6f8eda26cc56ac1d92",
      "nonce": "14",
      "transaction_index": "159",
      "from_address": "0xc84d8afb525268cbc95b6edf6ca35d727c273e1c",
      "from_address_label": null,
      "to_address": "0x3d9a49862b9735e6050f9d8d5540115ed5e3eb77",
      "to_address_label": null,
      "value": "0",
      "gas": "5272110",
      "gas_price": "11434748692",
      "input": "",
      "receipt_cumulative_gas_used": "14298989",
      "receipt_gas_used": "3485907",
      "receipt_status": "1",
      "block_timestamp": "2024-04-12T05:18:11.000Z",
      "block_number": "19637388",
      "block_hash": "0x7a86e910045253947b85f8c0986c7413888faf8962349eed3d62d286ec43a8f4",
      "nft_transfers": [],
      "erc20_transfers": [
        {
          "token_name": "TOX",
          "token_symbol": "TOX",
          "token_logo": null,
          "token_decimals": "8",
          "from_address": "0x800feb2b1092b93434048a17ecc6a1fad2687842",
          "from_address_label": null,
          "to_address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
          "to_address_label": null,
          "address": "0x3d9a49862b9735e6050f9d8d5540115ed5e3eb77",
          "log_index": 685,
          "value": "744397568560311000",
          "possible_spam": false,
          "verified_contract": false,
          "direction": "receive",
          "value_formatted": "7443975685.60311"
        }
      ],
      "method_label": null,
      "native_transfers": [],
      "summary": "Received 7,443,975,685.6031 TOX from 0x80...7842",
      "possible_spam": false,
      "category": "token receive"
    },
    //...
  ]
}

If you want a more detailed explanation of how this works, check out the official Wallet History documentation page, watch the video below, or join us in this guide! 

Also, if you wish to follow along in this tutorial, don’t forget to sign up with Moralis. You can create an account for free, and you’ll gain immediate access to our suite of industry-leading Web3 APIs! 

Want to Use the Industry's
Leading Web3 APIs?

Overview 

In today’s article, we’ll start by exploring the ins and outs of crypto wallet history APIs. From there, we’ll introduce you to Moralis’ Wallet API – a premier tool that not only provides the functionalities of a crypto wallet history API but also goes beyond that feature. In doing so, we’ll, among other things, introduce you to the Wallet History endpoint, which is the easiest way to get the history of a wallet. Next, we’ll dive into our main tutorial and show you how to get a user’s wallet transaction history in three steps: 

  1. Get a Moralis API Key
  2. Write a Script Calling the Wallet History Endpoint
  3. Run the Code

Lastly, to top things off, we’ll explore Moralis further and examine additional tools you can combine with the Wallet API to build sophisticated Web3 projects! 

So, if you’re looking to integrate wallet history into your dapps, this read is for you. Join us as we kickstart things by diving into the intricacies of crypto wallet history APIs. Let’s go! 

What is a Crypto Wallet History API?

Whether you’re building a decentralized exchange (DEX), portfolio tracker, Web3 wallet, or any other decentralized application (dapp), you’ll likely realize you need access to your users’ wallet histories. This includes everything from past balances to a complete record of all transactions! 

But why exactly do you need this data? 

To answer the query above, let’s use Web3 wallets as an example. Access to an address’ history is essential when building a Web3 wallet for numerous reasons. For one, it allows you to seamlessly display a user’s past transactions, which is a fundamental aspect of most crypto wallets. However, it additionally unlocks the potential for other prominent features, such as historical data analysis, transaction tracking, tax reports, etc. 

Example of data an application can get with a crypto wallet history API.

So, how can you get this data? 

From a conventional perspective, querying a blockchain network for this information has been quite a challenge, which is precisely why Web3 developers leverage crypto wallet history APIs to simplify the workflow.

But what is a crypto wallet history API? 

A crypto wallet history API (application programming interface) is a set of methods, rules, and protocols allowing you to seamlessly interact with a blockchain network to integrate wallet functionality and historical data into your dapps. Essentially, a crypto wallet history API makes the process of fetching historical wallet data from a blockchain network easy. And with these interfaces, you can leverage premade protocols and methods, meaning you don’t have to reinvent the wheel. In return, you can save lots of development time and resources when building dapps! 

So, which is the best crypto wallet history API? 

For the answer to this question, join us in the next section as we introduce you to Moralis’ industry-leading Wallet API! 

Introducing Moralis’ Wallet API – The Easiest Way to Get the History of a Crypto Wallet 

Moralis’ Web3 Wallet API is the ultimate tool for building wallets and integrating wallet functionality into your dapps. The Wallet API boasts an extensive array of features, unparalleled scalability, and exceptional flexibility, allowing you to build Web3 projects that will blow the competition out of the water!

Our Wallet API supports over 500 million addresses and all major blockchain networks, including Ethereum, Polygon, Optimism, Arbitrum, BNB Smart Chain (BSC), and many others. Consequently, building cross-chain-compatible dapps has never been easier than when working with Moralis.

Graphic art illustration - Moralis Wallet API title with code examples in the background

The Wallet API is equipped with a bunch of prominent features, and below, you’ll find a few examples: 

  • Token Balances: With a single line of code, you can get the token balances of any wallet, including ERC-20s, NFTs, native tokens, stablecoins, and much more. 
  • Wallet History: Get the entire transaction history of any wallet with a single endpoint. 
  • Net Worth: Avoid manual data aggregation and get the net worth of any ERC-20 wallet with just one API call.
  • Profitability: Query the profitability of a wallet, along with the loss/profit status for each token, without breaking a sweat.
  • Transaction Decodings: Access decoded transactions so you can seamlessly connect the dots and understand what’s happening on the blockchain. 
  • Address Labels: All transfer and transaction endpoints are equipped with fully enriched address labels for public addresses, including Coninbase, Uniswap, 1inch, and many more. 
  • ERC-4337 Compatibility: The Wallet API is ERC-4337 compatible. As such, it works perfectly with account abstraction, allowing you to effortlessly fetch token balances, transaction data, and transfers for any smart contract account. 

With an overview of Moralis’ Wallet API, let’s now explore our Wallet History endpoint – the ultimate solution for getting the history of a crypto wallet! 

Moralis’ Wallet History Endpoint 

Moralis’ Wallet History endpoint is the easiest way for you to get the transaction history of a crypto address. In fact, with this powerful feature, you only need one single API call to get all the data you need! 

Calling the Wallet History endpoint will return the entire history of a wallet across all events in chronological order. In addition, each event is fully enriched with summaries and categories for 15+ transaction types, meaning the wallet activity is decoded out of the box. 

To highlight the power of this feature, let’s show you what the Wallet History endpoint looks like in action with a simple script: 

import fetch from 'node-fetch';

const options = {
 method: 'GET',
 headers: {
   accept: 'application/json',
   'X-API-Key': 'YOUR_API_KEY'
 },
};

fetch(
 'https://deep-index.moralis.io/api/v2.2/wallets/0xd8da6bf26964af9d7eed9e03e53415d37aa96045/history?chain=eth&order=DESC',
 options
)
 .then((response) => response.json())
 .then((response) => console.log(response))
 .catch((err) => console.error(err));

Before calling the code above, you simply need to add your Moralis API key by replacing YOUR_API_KEY and configure the query parameters. In return, you’ll get a response that looks something like this: 

{
  //...
  "result": [
    {
      "hash": "0xdb50bd448ddc61166989477545fc95c76edcf6febdac5d6f8eda26cc56ac1d92",
      "nonce": "14",
      "transaction_index": "159",
      "from_address": "0xc84d8afb525268cbc95b6edf6ca35d727c273e1c",
      "from_address_label": null,
      "to_address": "0x3d9a49862b9735e6050f9d8d5540115ed5e3eb77",
      "to_address_label": null,
      "value": "0",
      "gas": "5272110",
      "gas_price": "11434748692",
      "input": "",
      "receipt_cumulative_gas_used": "14298989",
      "receipt_gas_used": "3485907",
      "receipt_status": "1",
      "block_timestamp": "2024-04-12T05:18:11.000Z",
      "block_number": "19637388",
      "block_hash": "0x7a86e910045253947b85f8c0986c7413888faf8962349eed3d62d286ec43a8f4",
      "nft_transfers": [],
      "erc20_transfers": [
        {
          "token_name": "TOX",
          "token_symbol": "TOX",
          "token_logo": null,
          "token_decimals": "8",
          "from_address": "0x800feb2b1092b93434048a17ecc6a1fad2687842",
          "from_address_label": null,
          "to_address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
          "to_address_label": null,
          "address": "0x3d9a49862b9735e6050f9d8d5540115ed5e3eb77",
          "log_index": 685,
          "value": "744397568560311000",
          "possible_spam": false,
          "verified_contract": false,
          "direction": "receive",
          "value_formatted": "7443975685.60311"
        }
      ],
      "method_label": null,
      "native_transfers": [],
      "summary": "Received 7,443,975,685.6031 TOX from 0x80...7842",
      "possible_spam": false,
      "category": "token receive"
    },
    //...
  ]
}

The response above contains a bunch of useful information, including a transaction hash, address labels, a category, a summary, and much more. The category and summary parameters are especially interesting, as you get decoded data directly without having to deal with any interpretation logic yourself: 

      //...
      "summary": "Received 7,443,975,685.6031 TOX from 0x80...7842",
      "possible_spam": false,
      "category": "token receive"
       //...

Benefits of the Wallet History Endpoint 

Now that you have familiarized yourself with the Wallet History endpoint, let’s dive into some benefits of this feature: 

  • Reduced Complexity: Avoid the unnecessary complexities of stitching together data from multiple APIs and endpoints. Get the history of any wallet with a single endpoint and dramatically reduce the number of API calls required. 
  • Complete Wallet Insight: With the Wallet History endpoint, you get the entire history of a wallet, including all native transactions, ERC-20 swaps, NFT transfers, and contract interactions, without breaking a sweat. This gives you in-depth insight into any wallet’s activity. 
  • Automatic Categories and Summaries: The Wallet API provides fully decoded data, mapping each transaction and transfer to one of 15+ categories. What’s more, each transaction has a ready-to-use summary parameter, providing a brief explanation of the event. 
Crypto wallets with their transaction fetched by an API - Graphic art illustration

3-Step Tutorial: How to Get the Transaction History of a Crypto Address Using Moralis’ Wallet API 

In this brief tutorial, we’ll demo the Wallet History endpoint by showing you how to get the history of a crypto address in three steps: 

  1. Get a Moralis API Key
  2. Write a Script Calling the Wallet History Endpoint
  3. Run the Code

However, you must deal with a few prerequisites before you can continue! 

Prerequisites 

The Wallet API works with multiple programming languages, including Python, TypeScript, etc. However, for this tutorial, we’ll be using JavaScript. As such, make sure you have the following ready before you move on: 

  • Node.js v.14+
  • Npm/Yarn

Step 1: Get a Moralis API Key 

To call the Wallet API, you need to have an API key. And to get one, you need a Moralis account. Therefore, start by signing up with Moralis and set up your first project! 

Next, go to the ”Settings” tab, scroll down until you find the ”API Keys” section, and copy your Moralis API key: 

Showing how to copy the crypto wallet history API key on the Moralis dashboard

Keep the key for now, as you’ll need it in the next step to initialize Moralis! 

Step 2: Write a Script Calling the Wallet History Endpoint 

Open your preferred IDE, set up a folder, and initialize a new project by running the following command in a new terminal: 

npm init

You can then run the terminal commands below in the root folder to install the required dependencies: 

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

Next, open your ”package.json” file and add ”type”: ”module”

Opening the ”package.json” file adding ”type”: ”module”: 

From here, create a new ”index.js” file and add the following code: 

import fetch from 'node-fetch';

const options = {
 method: 'GET',
 headers: {
   accept: 'application/json',
   'X-API-Key': 'YOUR_API_KEY'
 },
};

fetch(
 'https://deep-index.moralis.io/api/v2.2/wallets/0xd8da6bf26964af9d7eed9e03e53415d37aa96045/history?chain=eth&order=DESC',
 options
)
 .then((response) => response.json())
 .then((response) => console.log(response))
 .catch((err) => console.error(err));

Next, you need to make some minor configurations to the code. Start by replacing YOUR_API_KEY with the key you copied during the previous step. Next, configure the parameters to fit your query. 

That’s it; all you need to do from here is run the code!

Step 3: Run the Code 

For the final step, open a terminal and run this command in your project’s root folder to execute the script: 

node index.js

In return for running the code, you’ll get the entire history of the wallet in question. This will include all transactions, transfers, contract interactions, etc., along with out-of-the-box categories, summaries, and much more. Here’s an example of what it might look like: 

{
  //...
  "result": [
    {
      "hash": "0xdb50bd448ddc61166989477545fc95c76edcf6febdac5d6f8eda26cc56ac1d92",
      "nonce": "14",
      "transaction_index": "159",
      "from_address": "0xc84d8afb525268cbc95b6edf6ca35d727c273e1c",
      "from_address_label": null,
      "to_address": "0x3d9a49862b9735e6050f9d8d5540115ed5e3eb77",
      "to_address_label": null,
      "value": "0",
      "gas": "5272110",
      "gas_price": "11434748692",
      "input": "",
      "receipt_cumulative_gas_used": "14298989",
      "receipt_gas_used": "3485907",
      "receipt_status": "1",
      "block_timestamp": "2024-04-12T05:18:11.000Z",
      "block_number": "19637388",
      "block_hash": "0x7a86e910045253947b85f8c0986c7413888faf8962349eed3d62d286ec43a8f4",
      "nft_transfers": [],
      "erc20_transfers": [
        {
          "token_name": "TOX",
          "token_symbol": "TOX",
          "token_logo": null,
          "token_decimals": "8",
          "from_address": "0x800feb2b1092b93434048a17ecc6a1fad2687842",
          "from_address_label": null,
          "to_address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
          "to_address_label": null,
          "address": "0x3d9a49862b9735e6050f9d8d5540115ed5e3eb77",
          "log_index": 685,
          "value": "744397568560311000",
          "possible_spam": false,
          "verified_contract": false,
          "direction": "receive",
          "value_formatted": "7443975685.60311"
        }
      ],
      "method_label": null,
      "native_transfers": [],
      "summary": "Received 7,443,975,685.6031 TOX from 0x80...7842",
      "possible_spam": false,
      "category": "token receive"
    },
    //...
  ]
}

Congratulations; you now know how to use Moralis’ Wallet API to get the history of any crypto address! 

Use Cases for the Wallet History Endpoint

It doesn’t really matter what Web3 platform you’re building; odds are you’ll benefit significantly from our Wallet History endpoint. However, to give you a few examples, we’ll explore three prominent use cases down below: 

  • Cryptocurrency Wallets: Cryptocurrency wallets are websites and applications for storing and managing digital assets. These platforms typically feature an activity tab, giving users deep insight into past transfers. With the Wallet API, you can seamlessly build a timeline for any address with just one endpoint. 
  • Tax Tools: Tax tools are platforms that help users navigate the complicated world of cryptocurrency taxes. And to automate tax reporting, these dapps need access to past trading activities, which is where the Wallet History endpoint enters the equation. 
  • Decentralized Exchanges (DEXs): DEXs are peer-to-peer marketplaces for trading cryptocurrencies. In addition to swap functionality, most DEXs also give users an overview of their past transactions and transfers. And the easiest way to add a feature like this to your platform is to leverage the Wallet History endpoint.

Beyond the Wallet API – Exploring Moralis’ Web3 APIs Further 

Moralis is the industry’s premier Web3 API provider, and our suite of enterprise-grade development tools makes Web3 development a breeze. In addition to the Wallet API, we offer other tools that can aid you when building crypto projects. Below, you’ll find three examples:

  • NFT API: The NFT API is the industry’s leading tool for NFT data. With only single lines of code, you can effortlessly fetch NFT balances, metadata, real-time transfers, on-chain pricing data, etc. 
  • Token API: The Token API allows you to seamlessly get and integrate token data into your dapps. This includes real-time token prices, wallet balances, transfers, and much more. 
  • Streams API: The Streams API is the ultimate tool for monitoring on-chain events and setting up real-time alerts. With this interface, you can set up customized streams to get on-chain events sent directly to your project’s backend via Web3 webhooks. 
Graphic art image - showing the Moralis "M" Logo and a white title stating "Build Web3 Projects with Moralis' Crypto Wallet History API"

All of Moralis’ Web3 APIs are fully cross-chain compatible, meaning you can use our tools to build dapps on multiple blockchain networks, including Ethereum, Polygon, BSC, etc. 

Also, the interfaces mentioned above are only a few examples of our prominent APIs. If you want to explore all our tools, check out our official Web3 API page! 

Summary: Exploring the #1 Crypto Wallet History API

If you aren’t equipped with the proper tools, querying a wallet’s history can be tedious and time-consuming. Fortunately, tools like crypto wallet history APIs can help. But which is the best crypto wallet history API? 

Moralis’ Wallet API is the industry’s #1 tool for wallet data. With this premier interface, you only need our Wallet History endpoint to fetch the entire transaction history of a wallet. So, whether you’re building a cryptocurrency wallet, portfolio tracker, or any other platform, then your best option for wallet data is to check out Moralis’ Wallet API! 

If you found this crypto wallet history API tutorial interesting, check out other guides here at Moralis. For instance, read about our Gnosis API or learn how to get all owners of an ERC-20 token. Also, if you want to use the Wallet API in your development endeavors, don’t forget to sign up with Moralis!

Market Data API
Build amazing trading and portfolio dapps with this Market Data API. Keep users engaged with up-to-date data!
Market Data API
Related Articles
September 18, 2022

How to Create an NFT Gated Website in Django

February 9, 2024

How to Query Blockchain Data for Transactions, Balances, and More 

March 3, 2023

How to Build a Polygon Portfolio Tracker

January 28, 2023

Chainlink NFT Tutorial – How to Build a Chainlink NFT

January 18, 2023

Supabase Authentication – How to Authenticate Users on Supabase

December 27, 2022

Easy Web3 Programming Tutorial for Blockchain Development

December 5, 2023

Full Guide: What is Web3 as a Service?

October 2, 2022

Tutorial: How to Connect a Dapp to Polygon Network