> For the complete documentation index, see [llms.txt](https://docs.thehemera.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.thehemera.com/hemera-indexer/use-cases/opensea/trigger-and-function.md).

# Trigger and Function

The Opensea job is triggered when an Opensea-related transaction occurs or an event is produced. Specifically:

ref: [Opensea Event and Errors](https://docs.opensea.io/docs/seaport-events-and-errors)

* `OrderFulfilled`: When an order is successfully fulfilled

![Screenshot of Opensea](/files/rQjOIH35627cttMLda23)

```python
def parse_opensea_transaction_order_fulfilled_event(
        transaction: Transaction, contract_address: str, protocol_version: str = 1.6, fee_addresses: List[str] = []
) -> List[OpenseaLog]:
    results = []
    logs = transaction.receipt.logs
    for log in logs:
        if (
                log.topic0 == OPENSEA_EVENT_ABI_SIGNATURE_MAPPING["ORDER_FULFILLED_EVENT"]
                and log.address == contract_address
        ):
            opensea_transaction = decode_log(OPENSEA_EVENT_ABI_MAPPING["ORDER_FULFILLED_EVENT"], log)

            results.append(
                OpenseaLog(
                    orderHash="0x" + opensea_transaction["orderHash"].hex(),
                    offerer=opensea_transaction["offerer"],
                    zone=opensea_transaction["zone"],
                    recipient=opensea_transaction["recipient"],
                    offer=opensea_transaction["offer"],
                    consideration=opensea_transaction["consideration"],
                    block_timestamp=transaction.block_timestamp,
                    block_hash=transaction.block_hash,
                    block_number=transaction.block_number,
                    transaction_hash=transaction.hash,
                    log_index=log.log_index,
                    protocol_version=protocol_version,
                    fee_addresses=fee_addresses,
                )
            )

    return results
```

and the function to extract the data from the opensea event log:

```python
def transfer(self, opensea_logs: List[OpenseaLog]):
        for opensea_log in opensea_logs:
            yield OpenseaOrder(
                order_hash=opensea_log.orderHash,
                zone=opensea_log.zone,
                offerer=opensea_log.offerer,
                recipient=opensea_log.recipient,
                offer=opensea_log.offer,
                consideration=opensea_log.consideration,
                block_timestamp=opensea_log.block_timestamp,
                block_hash=opensea_log.block_hash,
                transaction_hash=opensea_log.transaction_hash,
                block_number=opensea_log.block_number,
                log_index=opensea_log.log_index,
                protocol_version=opensea_log.protocol_version,
            )
            offer = calculate_total_amount(opensea_log.offer)
            consideration = calculate_total_amount(opensea_log.consideration)
            fee = calculate_fee_amount(opensea_log.consideration, opensea_log.fee_addresses)

            opensea_transaciton_type = get_opensea_transaction_type(opensea_log.offer, opensea_log.consideration)
            if opensea_log.offerer == opensea_log.recipient:
                continue
            yield AddressOpenseaTransaction(
                address=opensea_log.offerer,
                related_address=opensea_log.recipient,
                is_offer=True,
                transaction_type=opensea_transaciton_type.value,
                order_hash=opensea_log.orderHash,
                zone=opensea_log.zone,
                offer=offer,
                consideration=consideration,
                fee=fee,
                transaction_hash=opensea_log.transaction_hash,
                block_number=opensea_log.block_number,
                log_index=opensea_log.log_index,
                block_timestamp=opensea_log.block_timestamp,
                block_hash=opensea_log.block_hash,
                protocol_version=opensea_log.protocol_version,
            )
            yield AddressOpenseaTransaction(
                address=opensea_log.recipient,
                related_address=opensea_log.offerer,
                is_offer=False,
                transaction_type=(
                    1 - opensea_transaciton_type.value
                    if opensea_transaciton_type.value <= 1
                    else opensea_transaciton_type.value
                ),
                order_hash=opensea_log.orderHash,
                zone=opensea_log.zone,
                offer=offer,
                consideration=consideration,
                fee=fee,
                transaction_hash=opensea_log.transaction_hash,
                block_number=opensea_log.block_number,
                log_index=opensea_log.log_index,
                block_timestamp=opensea_log.block_timestamp,
                block_hash=opensea_log.block_hash,
                protocol_version=opensea_log.protocol_version,
            )
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.thehemera.com/hemera-indexer/use-cases/opensea/trigger-and-function.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
