0

I want to query all in- and outcoming transactions for a given address. To do this I used the etherscanProvider.getHistory method. However f.e. this address AddrTo = 0x27E28fBc5250668006d82f811174bDC9F147F100 also received a "token transfer" of 5 USDC from address AddrFrom = 0x5E2aFDba5E5F96aed0DcD2760dDE4cFD2aa7b0bA via the smart contract SmartCtr = 0x07865c6e87b9f70255377e024ace6630c1eaa37f (see f.e. https://goerli.etherscan.io/address/0x27E28fBc5250668006d82f811174bDC9F147F100#tokentxns).

Now when I execute the above getHistory method for the AddrFrom, I get a result (with the to-address being SmartCtr) which is great. But when I do the same for the AddrTo, no such transaction is returned. I would have expected that there is a transaction with SmartCtr being the from-address.

Also if I execute this api: https://api-goerli.etherscan.io/api?module=account&action=txlist&address=0x27E28fBc5250668006d82f811174bDC9F147F100&startblock=0&endblock=99999999&page=1&offset=10 I do not get the desired transaction. Do I need to use some other API or need to go another way? Thanks in advance and best regards

2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Apr 22, 2023 at 0:17
  • You can use API services like Moralis web3api to get the erc20 token transfers. Let me know if you are interested I can show you an example using the Moralis sdk.
    – JohnVersus
    Apr 22, 2023 at 6:02

1 Answer 1

0

Found the solution in the meantime: One needs to use the contract API as specified in ethers here: https://docs.ethers.org/v5/api/contract/ Especially the example helped a lot so that my code looks now something like this:

    const provider = new ethers.providers.JsonRpcProvider(this.nodeUrl);
    const abi = [
      // Read-Only Functions
      "function balanceOf(address owner) view returns (uint256)",
      "function decimals() view returns (uint8)",
      "function symbol() view returns (string)",

      // Authenticated Functions
      "function transfer(address to, uint amount) returns (bool)",

      // Events
      "event Transfer(address indexed from, address indexed to, uint amount)"
    ];

    // create a contract object
    const erc20 = new ethers.Contract(smartContractAddress, abi, provider);
    try {
      // declare a filter
      const filterAddressTo = erc20.filters.Transfer(null, request.address);
      // apply the filter to get all transactions from the contract to the address
      const ctrResults = await erc20.queryFilter(filterAddressTo, -100000, "latest");
      for (const ctrResult of ctrResults) {
        const transaction = await ctrResult.getTransaction();
      ...
      }

Your Answer

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

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