1

Is it possible to detect, by looking at the transfer events, whether a NFT was sold from a Marketplace or not?

Basically I want to know if, in these cases, the safeTransferFrom method notifies the transfer event as if the from address is the owner of the token or if it does it using the actual address of the smart contract that is taking care of the sale.

1

1 Answer 1

0

It won't be straightforward to use the Transfer event. Instead, you may want to use the item_sold and the item_transferred events provided by OpenSea.

You can listen to them by using their Stream API.

You can subscribe to the collection you want with this code:

import { OpenSeaStreamClient, Network, EventType } from '@opensea/stream-js';
import { WebSocket } from 'ws';

const client = new OpenSeaStreamClient({
    network: Network.TESTNET,
    token: 'YOUR_API_KEY',
    connectOptions: {
        transport: WebSocket
    }
});

client.onEvents(
    'YOUR_COLLECTION_SLUG',
    [EventType.ITEM_SOLD, EventType.ITEM_TRANSFERRED],
    (event) => {
      console.log(event)
    }
);

This is a example of the item_sold event:

{
  event_type: 'item_sold',
  payload: {
    closing_date: '2023-05-22T03:41:37.000000+00:00',
    collection: { slug: 'tm-nissan-370z-nismo-1-8' },
    event_timestamp: '2023-05-22T03:41:37.000000+00:00',
    is_private: false,
    item: {
      chain: [Object],
      metadata: [Object],
      nft_id: 'mumbai/0xa2bf19b63976fe14542e27ae7713f2bce34ce2bb/3845549538239791443866238707771342366788264520871453379120441143580141027409',
      permalink: 'https://testnets.opensea.io/assets/mumbai/0xa2bf19b63976fe14542e27ae7713f2bce34ce2bb/3845549538239791443866238707771342366788264520871453379120441143580141027409'
    },
    listing_type: null,
    maker: { address: '0xfe02781cc0fe76bfd2d211430bfa97d2889fd853' },
    order_hash: '0x931e8da185fef54e85bc5b89c08758460d8d9a76d65dcf69b07a2d537f7d6d19',
    payment_token: {
      address: '0x0000000000000000000000000000000000000000',
      decimals: 18,
      eth_price: '0.000471660000000',
      name: 'Matic',
      symbol: 'MATIC',
      usd_price: '0.849912000000000000'
    },
    protocol_address: '0x00000000000000adc04c56bf30ac9d3c0aaf14dc',
    protocol_data: { parameters: [Object], signature: null },
    quantity: 1,
    sale_price: '1000000000000000',
    taker: { address: '0x45dd8e9387d773a652f16afd54e61898ff3e6549' },
    transaction: {
      hash: '0x0276cf554d9d056e840ac51bd3f870840ee01f3ce251eb5cfe839b28d18cf238',
      timestamp: '2023-05-22T03:41:37.000000+00:00'
    }
  },
  sent_at: '2023-05-22T03:41:37.802491+00:00'
}

And this is a example of the item_transferred event:

{
  event_type: 'item_transferred',
  payload: {
    collection: { slug: 'tm-nissan-370z-nismo-1-8' },
    event_timestamp: '2023-05-22T03:41:37.000000+00:00',
    from_account: { address: '0xfe02781cc0fe76bfd2d211430bfa97d2889fd853' },
    item: {
      chain: [Object],
      metadata: [Object],
      nft_id: 'mumbai/0xa2bf19b63976fe14542e27ae7713f2bce34ce2bb/3845549538239791443866238707771342366788264520871453379120441143580141027409',
      permalink: 'https://testnets.opensea.io/assets/mumbai/0xa2bf19b63976fe14542e27ae7713f2bce34ce2bb/3845549538239791443866238707771342366788264520871453379120441143580141027409'
    },
    quantity: 1,
    to_account: { address: '0x45dd8e9387d773a652f16afd54e61898ff3e6549' },
    transaction: {
      hash: '0x0276cf554d9d056e840ac51bd3f870840ee01f3ce251eb5cfe839b28d18cf238',
      timestamp: '2023-05-22T03:41:37.000000+00:00'
    }
  },
  sent_at: '2023-05-22T03:41:37.698849+00:00'
}

The list of possible events you can listen can be found in the EventType definition:

export declare enum EventType {
    ITEM_METADATA_UPDATED = "item_metadata_updated",
    ITEM_LISTED = "item_listed",
    ITEM_SOLD = "item_sold",
    ITEM_TRANSFERRED = "item_transferred",
    ITEM_RECEIVED_OFFER = "item_received_offer",
    ITEM_RECEIVED_BID = "item_received_bid",
    ITEM_CANCELLED = "item_cancelled",
    COLLECTION_OFFER = "collection_offer",
    TRAIT_OFFER = "trait_offer"
}

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.