1

I need to select special transactions like these:
enter image description here
That is, a sale transaction, with a certain price (0 ether, as here). As a result of the work carried out, I can determine which nft from which contract were transferred to whom and by whom. But I still don't understand how etherscan determines that this is a Sale action and finds out the price? Can I do this using the web3 api? Transaction

2 Answers 2

2

I would like to add on to the previous answer for your specific case.

Since you are looking for Sales on opensea, You will use web3.eth.getTransaction() and loop through the logs array that is returned for the topics array of each log.

If the "0x9d9af8e38d66c62e2c12f0225249fd9d721c54b83f48d9352c97c6cacdcb6f31" topic is included in the topics array, then that means it is a sale on opensea seaport contract. You can find this by looking through the seaport contract on etherscan.

To find the value in wei of the transaction you can use web3.eth.getTransactionReceipt()

to answer your comment, "0x9d9af8e38d66c62e2c12f0225249fd9d721c54b83f48d9352c97c6cacdcb6f31" is a topic of the OrderFulfilled event that is emitted by the opensea seaport contract when an order is completed. Here is the format of this event from the contract code.

/*
 *  Memory layout in _prepareBasicFulfillmentFromCalldata of
 *  data for OrderFulfilled
 *
 *   event OrderFulfilled(
 *     bytes32 orderHash,
 *     address indexed offerer,
 *     address indexed zone,
 *     address fulfiller,
 *     SpentItem[] offer,
 *       > (itemType, token, id, amount)
 *     ReceivedItem[] consideration
 *       > (itemType, token, id, amount, recipient)
 *   )
 *
 *  - 0x00: orderHash
 *  - 0x20: fulfiller
 *  - 0x40: offer offset (0x80)
 *  - 0x60: consideration offset (0x120)
 *  - 0x80: offer.length (1)
 *  - 0xa0: offerItemType
 *  - 0xc0: offerToken
 *  - 0xe0: offerIdentifier
 *  - 0x100: offerAmount
 *  - 0x120: consideration.length (1 + additionalRecipients.length)
 *  - 0x140: considerationItemType
 *  - 0x160: considerationToken
 *  - 0x180: considerationIdentifier
 *  - 0x1a0: considerationAmount
 *  - 0x1c0: considerationRecipient
 *  - ...
 */
2
  • What does "0x9d9af8e38d66c62e2c12f0225249fd9d721c54b83f48d9352c97c6cacdcb6f31" represent?
    – Ismael
    Commented Jan 25, 2023 at 4:21
  • 1
    I'll update my answer so I can add images Commented Jan 25, 2023 at 17:10
2

Yes, you can.

There are a number of ways ERC20/ERC721 differ.

API’s/node providers allow filtering dependant on certain aspects of transaction’s data to deduce what happened in that transaction. This can be done in a multitude of ways, depending on what precisely you’re looking to achieve.

In your case, look for the transfer signature (first 4 bytes of tx.signature yields this) in transaction logs matching ERC721 (ERC20 topics.length == 3, ERC721 topics.length == 4). You can then deduce which are transactions of interest by inspecting the value passed in the transaction via web3.eth.getTransaction().

This is essentially what etherscan does in certain places to display a practical user interface, but we can use things like Alchemy or Infura to achieve the same (likely more tailored) thing.

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.