I'm trying to figure out how to get a history of values for a specific ERC721 token of known contract address.

I want to do some maths in solidity and do not want to do all that in web2; therefore, I want to get the transaction history of the token within solidity.

Is there a way to do this? I know that Moralis has an API that does the same, but I want this in my smart contract.


Ankesh S

  • You can get the transaction history from etherscan api too
    – Julissa DC
    Jun 23, 2022 at 12:23
  • I don't need API, I want to have it built into the smart contract.
    – Ankesh
    Jun 23, 2022 at 12:39
  • Are you sure you want to store all that info inside the contract? Storage is pretty expensive
    – Julissa DC
    Jun 23, 2022 at 16:06
  • No, I don't want to store info in a smart contract, I just want to fetch the already stored information. The transactions history is already there in the Ethereum blockchain, I just want to fetch that information,
    – Ankesh
    Jun 24, 2022 at 11:16

1 Answer 1


You can write a new event containing the transaction data you want and emit it within the _transfer function. You can query for these events on the frontend.

  • He actually said he did not want to do this outside of the contract. Jun 26, 2022 at 4:53
  • @Itération122442 It sounds like he wants to avoid storing extra info on-chain, yet avoid fetching all the transactions using the frontend. To my knowledge, this is not possible. Transaction history is not stored in a single data structure that can just be retrieved. Transactions are spread over different blocks. He'll either have to use my solution or store extra data on-chain.
    – Fibo36
    Jun 26, 2022 at 18:47

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.