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

# EventLog.clone

> Deep clone event log including topics and data

<Card title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/event-log.ts">
  Run EventLog examples in the interactive playground
</Card>

<Tabs />

## Clone Behavior

`clone()` creates deep copies of mutable fields:

* **Topics array** - New array with same topic references
* **Data** - New Uint8Array with copied bytes
* **Immutable fields** - Shared references (address, hashes, numbers)

```typescript theme={null}
import { EventLog } from 'tevm';

const original = EventLog({
  address: contractAddress,
  topics: [topic0, topic1],
  data: new Uint8Array([1, 2, 3]),
  blockNumber: 100n,
});

const cloned = original.clone();

// Topics array is independent
cloned.topics.push(newTopic); // Error: topics is readonly

// Data is independent
cloned.data[0] = 99;
console.log(original.data[0]); // 1 (unchanged)

// Immutable fields are shared
console.log(original.address === cloned.address); // true (same reference)
console.log(original.blockNumber === cloned.blockNumber); // true
```

## Usage Patterns

### Cloning for Modification

```typescript theme={null}
import { EventLog } from 'tevm';

const log = EventLog({
  address: contractAddress,
  topics: [eventSignature],
  data: eventData,
  removed: false,
});

// Clone before modifying
const modified = EventLog.clone(log);
(modified as any).removed = true; // Modify clone

console.log(log.removed); // false (original unchanged)
console.log(modified.removed); // true
```

### Cloning Collection

```typescript theme={null}
import { EventLog } from 'tevm';

const logs = [log1, log2, log3];

// Clone all logs
const cloned = logs.map(log => log.clone());

// Or using static method
const cloned2 = logs.map(EventLog.clone);
```

### Preventing Mutation

```typescript theme={null}
import { EventLog } from 'tevm';

function processLog(log: EventLog) {
  // Clone to prevent external mutations
  const safeCopy = log.clone();

  // Modify safely
  // ... process safeCopy ...

  return result;
}

const original = EventLog({ /* ... */ });
const result = processLog(original);
// original is unchanged
```

## Performance

Clone creates new arrays and copies bytes:

* **Topics array allocation** - Small overhead (typically 1-4 elements)
* **Data copy** - Proportional to data size (typically 0-1024 bytes)
* **Immutable fields** - Zero overhead (shared references)

For read-only operations, cloning is unnecessary. Only clone when modifications are needed.

## See Also

* [from](/primitives/eventlog/from) - Create new log
* [Fundamentals](/primitives/eventlog/fundamentals) - Event log structure
