As the title says, I have my Solidity smart contract and I am trying to import in ti some public data from the Uniswap contract. In particular I would like to have the tx data stored in my contract (let's say the latest 10 tx).

I don't want to do this using web3.js interface, but I would like this to happen within my contract.

I was thinking of using Oraclize somehow (I never used this). Would it be possible to query a deployed smart contract and get past tx data? What would be the best way?

  • Historical data cannot be retrieved on-chain (i.e., it cannot be read from inside a contract function). Nov 23, 2020 at 12:24
  • Yes I know this, but I was wondering if this can be "bypassed" using Oraclize or similar to read this info directly from Etherscan page (i.e. querying the contract page)
    – 4NDR34
    Nov 23, 2020 at 13:07
  • What do you think Oraclize does other than interacting with your contract via web3.js or similar? Nov 23, 2020 at 13:08
  • You are right, I think I expressed my question in a wrong way. I would like to retrieve data from a random contract (let's say Uniswap), just by using a solidity smart contract code. Let's say I am writing my .sol code and I would like to have in it some hystorical data from another contract. Would this be possible with Oraclize? I am asking cause I never used it and I am wondering what should I actually query on etherscan to get those past tx data.
    – 4NDR34
    Nov 23, 2020 at 13:17

1 Answer 1


It sounds like you're looking to get external data via an API. To do this, you'll have to use an oracle.

Without using web3.js or other way of interacting with the chain, you'll need to interact with a service that does interact with the chain, an API or otherwise. Etherscan has an API that can probably provide what you're looking for.

Once you get those 2 pieces together, namely:

  1. The API you want to call
  2. The data you want back

Please note

This will be how to pull data in a centralized way. Please use multiple data sources and multiple chainlink oracles to get a decentralized aggregate answer for production instances

You can make a Chainlink API call then to get the data. A full contract would look something like below. Just swap out the API and the path for what your looking for. You can find remix examples in the chainlink docs as well.

pragma solidity ^0.6.0;

import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";

contract APIConsumer is ChainlinkClient {
    uint256 public volume;
    address private oracle;
    bytes32 private jobId;
    uint256 private fee;
     * Network: Kovan
     * Oracle: Chainlink - 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
     * Job ID: Chainlink - 29fa9aa13bf1468788b7cc4a500a45b8
     * Fee: 0.1 LINK
    constructor() public {
        oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
        jobId = "29fa9aa13bf1468788b7cc4a500a45b8";
        fee = 0.1 * 10 ** 18; // 0.1 LINK
     * Create a Chainlink request to retrieve API response, find the target
     * data, then multiply by 1000000000000000000 (to remove decimal places from data).
    function requestVolumeData() public returns (bytes32 requestId) 
        Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
        // Set the URL to perform the GET request on
        request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
        // Set the path to find the desired data in the API response, where the response format is:
        // {"RAW":
        //   {"ETH":
        //    {"USD":
        //     {
        //      "VOLUME24HOUR": xxx.xxx,
        //     }
        //    }
        //   }
        //  }
        request.add("path", "RAW.ETH.USD.VOLUME24HOUR");
        // Multiply the result by 1000000000000000000 to remove decimals
        int timesAmount = 10**18;
        request.addInt("times", timesAmount);
        // Sends the request
        return sendChainlinkRequestTo(oracle, request, fee);
     * Receive the response in the form of uint256
    function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId)
        volume = _volume;

Note: I am a Chainlink DevRel

  • Yes that's exactly what I wanted to know, thank you. I'll try like this. So somehow I will need to call Etherscan API asking to give me back the tx data of a particular token (ex. sender receiver amount)
    – 4NDR34
    Nov 23, 2020 at 13:38
  • Exactly. You can browse around the Etherscan docs and find out what you're looking for, then make the API call for it. Feel free to jump into the Chainlink discord for more support: discord.gg/2YHSAey. Also please remember to accept the answer if it works for what you're looking for. Nov 23, 2020 at 13:44

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.