I'm trying to fetch most recent DAI transfers for this address 0x6b175474e89094c44da98b954eedeac495271d0f, and retrieve information about them such as address, etc. I feel like I'm missing understanding of fundamentals in order to do it properly.

Steps I had taken

I connected to metamask and added web3-provider to be able to retrieve library from context.

I don't understand how to retrieve DAI blocks only. What I did was:

  • Retrieved ABI for the smart contract under this address from https://etherscan.io/address/0x6b175474e89094c44da98b954eedeac495271d0f#code
  • Created contract with contractAddress, abi and ethers lib
  • Retrieved latest block number
  • Retrieved blocks using iterator and decremented iterator after every loop run

Actual code:

const contractAddress = '0x6b175474e89094c44da98b954eedeac495271d0f';
const contract = new ethers.Contract(contractAddress, ABI, library);
const recent = await contract.provider.getBlockNumber();
const next = await contract.provider.getBlock(recent);
const next2 = await contract.provider.getBlock(recent - 1);

Example of what I received:

    "hash": "0xf898356b6eb8f5ad645ba3a9b869a8d63bbc3f1fc02e6be41ba582520d0d5d68",
    "parentHash": "0xa3e23363bfb22b68a2d100d013e4819a4e1e2488a09de89b9e2a29bb07d44ca3",
    "number": 15824974,
    "timestamp": 1666699379,
    "nonce": "0x0000000000000000",
    "difficulty": 0,
    "gasLimit": {
        "type": "BigNumber",
        "hex": "0x01c9c380"
    "gasUsed": {
        "type": "BigNumber",
        "hex": "0xb6b595"
    "miner": "0x0000000000000000000000000000000000000001",
    "extraData": "0x",
    "transactions": [
    "baseFeePerGas": {
        "type": "BigNumber",
        "hex": "0x0335b6a98d"
    "_difficulty": {
        "type": "BigNumber",
        "hex": "0x00"

My assumption was that If I were to copy the hash from the response I'd be able to view the transaction in etherscan, but I was wrong. Following link returns no match https://etherscan.io/tx/0xf898356b6eb8f5ad645ba3a9b869a8d63bbc3f1fc02e6be41ba582520d0d5d68

Does the code I wrote get blocks related to DAI only? Or am I missing something? Why doesn't the tx appear in etherscan? How do I filter transactions basing on sender? To put it in other words - how do I mimick etherscan view for displaying ERC-20 token? I would really appreciate any kind of enlightening!

1 Answer 1


That is the hash of block number 15824974. You're dumping the content of the block. Blocks are batches of transactions with a hash of the previous block in the chain. This links blocks together (in a chain) because hashes are cryptographically derived from the block data.

You can see the block on etherscan via this URL https://etherscan.io/block/15824974, but you can also see the same thing on this link https://etherscan.io/block/0xf898356b6eb8f5ad645ba3a9b869a8d63bbc3f1fc02e6be41ba582520d0d5d68 (Note the same hash in the URL as you have)

It's not that simple to get transaction history. It's not indexed by the blockchain, not by a standard node, "out-of-the-box". As of today, the size of ethereum blockchain is around 950 GB. For many cases, you can probably rely on Etherscan.

In order to get the transactions you'd have to use Etherscan as a provider in ethers and call the getHistory method. Please note that not all providers support the getHistory method.

The following code snippet will list the transactions to the address you specified in the last 10 blocks. (There might be no transactions when you query it so just tweak the numbers)

const ethers = require("ethers");

let address = "0x6b175474e89094c44da98b954eedeac495271d0f";
let provider = new ethers.providers.EtherscanProvider();

async function main() {
  const currentBlock = await provider.getBlockNumber()
  const startBlock = currentBlock - 10;
  const endBlock = currentBlock;

  let history = await provider.getHistory(address, startBlock, endBlock);

  history.forEach((tx) => {


For more information please head over to ethers documentation about the EtherscanProvider - https://docs.ethers.io/v5/api/providers/api-providers/#EtherscanProvider

If you'd like to further filter the transactions (e.g. particular token) then you need an appropriate provider to do that OR do some manual filtering in javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.