# Event fields with \`nil\` type

**URL:** <https://forum.flow.com/t/event-fields-with-nil-type/634>\
**Category:** ⚙️ Flow SDKs\
**Created:** [November 12, 2020, 4:47pm UTC](https://forum.flow.com/t/event-fields-with-nil-type/634 "2020-11-12T16:47:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![flowjosh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/flowjosh/32/362_2.png) [@flowjosh](https://forum.flow.com/u/flowjosh)\
**Post date:** [November 12, 2020, 4:47pm UTC](https://forum.flow.com/t/event-fields-with-nil-type/634/1 "2020-11-12T16:47:11Z")

</div>

Copied from discord:

A lot of event field types ( `cadence.Type` from `TransactionResult.Events[].Value.EventType.Fields[].Type` ) has a `nil` value, is this expected?

`EventType.Fields[].Type` with `nil` values:

```auto
flow.AccountKeyAdded publicKey
flow.AccountKeyRemoved publicKey
flow.AccountCodeUpdated codeHash
flow.AccountCodeUpdated contracts
A.0b2a3299cc857e29.TopShot.Withdraw from
A.c1e4f4f4c4257510.Market.MomentWithdrawn owner
A.0b2a3299cc857e29.TopShot.Deposit to
A.c1e4f4f4c4257510.Market.CutPercentageChanged seller
A.c1e4f4f4c4257510.Market.MomentListed seller
A.ead892083b3e2c6c.DapperUtilityCoin.TokensWithdrawn from
A.ead892083b3e2c6c.DapperUtilityCoin.TokensDeposited to
A.e544175ee0461c4b.TokenForwarding.ForwardedDeposit from
A.c1e4f4f4c4257510.Market.MomentPurchased seller
A.0b2a3299cc857e29.TopShot.PlayCreated metadata
A.1654653399040a61.FlowToken.TokensWithdrawn from
A.1654653399040a61.FlowToken.TokensDeposited to

```

Other event field types has the correct type (e.g. `UInt64` , `Address` , etc)

---

<div class="post-metadata">

**Author:** ![flowjosh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/flowjosh/32/362_2.png) [@flowjosh](https://forum.flow.com/u/flowjosh)\
**Post date:** [November 12, 2020, 4:48pm UTC](https://forum.flow.com/t/event-fields-with-nil-type/634/2 "2020-11-12T16:48:24Z")

</div>

This is because the fields from those events are optionals. They are often used to show who the owner of the resource is when the event is emitted, but if the resource isn’t stored in an account when the event is emitted, the field is `nil`.

---

<div class="post-metadata">

**Author:** ![yondercode](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yondercode](https://forum.flow.com/u/yondercode)\
**Post date:** [November 13, 2020, 2:16am UTC](https://forum.flow.com/t/event-fields-with-nil-type/634/3 "2020-11-13T02:16:07Z")

</div>

I see, I think `EventType.Fields[].Type` should contain a `cadence.OptionalType` value rather than `nil` if an event field type is an optional.

Because even event field optionals with a value has a `nil` value in their `EventType.Fields[].Type`

For example the first event in this transaction: `0x2ea2e9ba55600c4662237cf07c0fffb0d1a245cb676af93503fc46cecfd373e5`, the `from` field that I get from `Events[0].Value.Fields[1]` has a value of address `0xdf73817b133cd960` but `Events[0].Value.EventType.Fields[1].Type` is `nil`

---

<div class="post-metadata">

**Author:** ![flowjosh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/flowjosh/32/362_2.png) [@flowjosh](https://forum.flow.com/u/flowjosh)\
**Post date:** [November 16, 2020, 3:01pm UTC](https://forum.flow.com/t/event-fields-with-nil-type/634/4 "2020-11-16T15:01:52Z")

</div>

@bastian Do you think this sounds reasonable? ☝

---

<div class="post-metadata">

**Author:** ![bastian](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/bastian/32/183_2.png) [@bastian](https://forum.flow.com/u/bastian)\
**Post date:** [November 16, 2020, 5:08pm UTC](https://forum.flow.com/t/event-fields-with-nil-type/634/5 "2020-11-16T17:08:04Z")

</div>

@yondercode I think you’re right, this looks like a bug. Could you please open a bug report in the Cadence repo?

---

<div class="post-metadata">

**Author:** ![yondercode](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yondercode](https://forum.flow.com/u/yondercode)\
**Post date:** [November 17, 2020, 7:53am UTC](https://forum.flow.com/t/event-fields-with-nil-type/634/6 "2020-11-17T07:53:26Z")

</div>

@bastian I just added it: [The field `Type` in `cadence.Field` returns `nil` for optional types · Issue #456 · onflow/cadence · GitHub](https://github.com/onflow/cadence/issues/456) I hope the formatting is correct 😁

For now I’m using `json.Encode` on the value which provide the correct type for optionals.

However it might not work for all events as some field’s value are actually `nil` (since it’s an optional) so it’ll be better to have the type correctly defined in `cadence.Field` as the source of truth for the type of event fields.

---

<div class="post-metadata">

**Author:** ![bastian](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/bastian/32/183_2.png) [@bastian](https://forum.flow.com/u/bastian)\
**Post date:** [November 17, 2020, 11:41pm UTC](https://forum.flow.com/t/event-fields-with-nil-type/634/7 "2020-11-17T23:41:48Z")

</div>

@yondercode Thank you for reporting the issue. I opened this PR to fix it: [https://github.com/onflow/cadence/pull/458](https://github.com/onflow/cadence/pull/458)
