> ## Documentation Index
> Fetch the complete documentation index at: https://docs.starknet.io/llms.txt
> Use this file to discover all available pages before exploring further.

# core::starknet::event::Event

A trait for handling serialization and deserialization of events.
Events in Starknet are stored in transaction receipts as a combination of keys and data fields.
This trait provides the methods needed to serialize event data into these fields and deserialize
them back into their original form.
This trait can easily be derived using the `#[derive(starknet::Event)]` attribute.
Fields can be marked as keys using the `#[key]` attribute to serialize them as event keys.

## Signature

```rust theme={null}
pub trait Event
```

## Examples

```rust theme={null}
#[derive(Drop, starknet::Event)]
pub struct Transfer {
    #[key]
    pub from: ContractAddress,
    #[key]
    pub to: ContractAddress,
    pub amount: u256,
}
```

## Trait functions

### append\_keys\_and\_data

Serializes the keys and data for event emission.
The keys array will contain:

* The event name selector as the first key
* Any fields marked with #key as subsequent keys

The data array will contain all non-key fields.

#### Signature

```rust theme={null}
fn append_keys_and_data(self: @T, ref keys: Array, ref data: Array)
```

### deserialize

Deserializes events keys and data back into the original event structure.
Returns `None` if deserialization fails.

#### Signature

```rust theme={null}
fn deserialize(ref keys: Span, ref data: Span) -> Option
```
