|
| 1 | +# Non-Fungible Token Event |
| 2 | + |
| 3 | +Version `1.0.0` |
| 4 | + |
| 5 | +## Summary |
| 6 | + |
| 7 | +Standard interfaces for NFT contract actions. |
| 8 | + |
| 9 | +## Motivation |
| 10 | + |
| 11 | +NFT-driven apps perform many similar actions. |
| 12 | +For example - `minting`, `burning` and `transferring`. |
| 13 | +Each app may have their own way of performing these actions. |
| 14 | +This introduces inconsistency in capturing these events. |
| 15 | +This extension addresses that. |
| 16 | + |
| 17 | +It's common for NFT apps to transfer many or one token at a time. |
| 18 | +Other applications need to track these and similar events consistently. |
| 19 | +If not, tracking state across many NFT-driven apps become infeasible. |
| 20 | + |
| 21 | +We need a standard way to capture events. |
| 22 | +This was discussed here https://github.com/near/NEPs/issues/254. |
| 23 | + |
| 24 | +## Events |
| 25 | + |
| 26 | +Many apps use different interfaces that represent the same action. |
| 27 | +This interface standardizes that process by introducing event logs. |
| 28 | +There is no Event NEP yet, so this standard paves the road to that. |
| 29 | + |
| 30 | +Events use standard logs capability of NEAR and defined as a convention. |
| 31 | +Events are log entries that start with `EVENT_JSON:` prefix followed by a single valid JSON document of the following interface: |
| 32 | + |
| 33 | +```ts |
| 34 | +// Interface to capture data |
| 35 | +// about an event |
| 36 | +// Arguments |
| 37 | +// * `standard`: name of standard e.g. nep171 |
| 38 | +// * `version`: e.g. 1.0.0 |
| 39 | +// * `event`: string |
| 40 | +// * `data`: associate event data |
| 41 | +interface EventLogData { |
| 42 | + standard: string, |
| 43 | + version: string, |
| 44 | + event: string, |
| 45 | + data?: unknown, |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +#### Valid event logs: |
| 50 | + |
| 51 | +```js |
| 52 | +EVENT_JSON:{"standard": "nepXXX", "version": "1.0.0", "event": "xyz_is_triggered"} |
| 53 | +``` |
| 54 | + |
| 55 | +```js |
| 56 | +EVENT_JSON:{ |
| 57 | + "standard": "nepXXX", |
| 58 | + "version": "1.0.0", |
| 59 | + "event": "xyz_is_triggered" |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +```js |
| 64 | +EVENT_JSON:{"standard": "nepXXX", "version": "1.0.0", "event": "xyz_is_triggered", "data": {"triggered_by": "foundation.near"}} |
| 65 | +``` |
| 66 | + |
| 67 | +#### Invalid event logs: |
| 68 | + |
| 69 | +* Two events in a single log entry (instead, call `log` for each individual event) |
| 70 | +``` |
| 71 | +EVENT_JSON:{"standard": "nepXXX", "version": "1.0.0", "event": "xyz_is_triggered"} |
| 72 | +EVENT_JSON:{"standard": "nepXXX", "version": "1.0.0", "event": "xyz_is_triggered"} |
| 73 | +``` |
| 74 | +* Invalid JSON data |
| 75 | +``` |
| 76 | +EVENT_JSON:invalid json |
| 77 | +``` |
| 78 | + |
| 79 | +## Interface |
| 80 | + |
| 81 | +Non-Fungible Token Events MUST have `standard` set to `"nep171"`, standard version set to `"1.0.0"`, `event` value is one of `nft_mint`, `nft_burn`, `nft_transfer`, and `data` must be of one of the following relavant types: `NftMintLog[] | NftTransferLog[] | NftBurnLog[]`: |
| 82 | + |
| 83 | +```ts |
| 84 | +interface EventLogData { |
| 85 | + standard: "nep171", |
| 86 | + version: "1.0.0", |
| 87 | + event: "nft_mint" | "nft_burn" | "nft_transfer", |
| 88 | + data: NftMintLog[] | NftTransferLog[] | NftBurnLog[], |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +```ts |
| 93 | +// An event log to capture token minting |
| 94 | +// Arguments |
| 95 | +// * `owner_id`: "account.near" |
| 96 | +// * `token_ids`: ["1", "abc"] |
| 97 | +// * `memo`: optional message |
| 98 | +interface NftMintLog { |
| 99 | + owner_id: string, |
| 100 | + token_ids: string[], |
| 101 | + memo?: string |
| 102 | +} |
| 103 | + |
| 104 | +// An event log to capture token burning |
| 105 | +// Arguments |
| 106 | +// * `owner_id`: owner of tokens to burn |
| 107 | +// * `authorized_id`: approved account to burn, if applicable |
| 108 | +// * `token_ids`: ["1","2"] |
| 109 | +// * `memo`: optional message |
| 110 | +interface NftBurnLog { |
| 111 | + owner_id: string, |
| 112 | + authorized_id?: string, |
| 113 | + token_ids: string[], |
| 114 | + memo?: string |
| 115 | +} |
| 116 | + |
| 117 | +// An event log to capture token transfer |
| 118 | +// Arguments |
| 119 | +// * `authorized_id`: approved account to transfer |
| 120 | +// * `old_owner_id`: "owner.near" |
| 121 | +// * `new_owner_id`: "receiver.near" |
| 122 | +// * `token_ids`: ["1", "12345abc"] |
| 123 | +// * `memo`: optional message |
| 124 | +interface NftTransferLog { |
| 125 | + authorized_id?: string, |
| 126 | + old_owner_id: string, |
| 127 | + new_owner_id: string, |
| 128 | + token_ids: string[], |
| 129 | + memo?: string |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +## Examples |
| 134 | + |
| 135 | +Single owner batch minting (pretty-formatted for readability purposes): |
| 136 | + |
| 137 | +```js |
| 138 | +EVENT_JSON:{ |
| 139 | + "standard": "nep171", |
| 140 | + "version": "1.0.0", |
| 141 | + "event": "nft_mint", |
| 142 | + "data": [ |
| 143 | + {"owner_id": "foundation.near", "token_ids": ["aurora", "proximitylabs"]} |
| 144 | + ] |
| 145 | +} |
| 146 | +``` |
| 147 | + |
| 148 | +Different owners batch minting: |
| 149 | + |
| 150 | +```js |
| 151 | +EVENT_JSON:{ |
| 152 | + "standard": "nep171", |
| 153 | + "version": "1.0.0", |
| 154 | + "event": "nft_mint", |
| 155 | + "data": [ |
| 156 | + {"owner_id": "foundation.near", "token_ids": ["aurora", "proximitylabs"]}, |
| 157 | + {"owner_id": "user1.near", "token_ids": ["meme"]} |
| 158 | + ] |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +Different events (separate log entries): |
| 163 | + |
| 164 | +```js |
| 165 | +EVENT_JSON:{ |
| 166 | + "standard": "nep171", |
| 167 | + "version": "1.0.0", |
| 168 | + "event": "nft_burn", |
| 169 | + "data": [ |
| 170 | + {"owner_id": "foundation.near", "token_ids": ["aurora", "proximitylabs"]}, |
| 171 | + ] |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +```js |
| 176 | +EVENT_JSON:{ |
| 177 | + "standard": "nep171", |
| 178 | + "version": "1.0.0", |
| 179 | + "event": "nft_transfer", |
| 180 | + "data": [ |
| 181 | + {"old_owner_id": "user1.near", "new_owner_id": "user2.near", "token_ids": ["meme"], "memo": "have fun!"} |
| 182 | + ] |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +## Further methods |
| 187 | + |
| 188 | +Note that the example events covered above cover two different kinds of events: |
| 189 | +1. Events that are not specified in the NFT Standard (`nft_mint`, `nft_burn`) |
| 190 | +2. An event that is covered in the [NFT Core Standard](https://nomicon.io/Standards/NonFungibleToken/Core.html#nft-interface). (`nft_transfer`) |
| 191 | + |
| 192 | +This event standard also applies beyond the three events highlighted here, where future events follow the same convention of as the second type. For instance, if an NFT contract uses the [approval management standard](https://nomicon.io/Standards/NonFungibleToken/ApprovalManagement.html), it may emit an event for `nft_approve` if that's deemed as important by the developer community. |
| 193 | + |
| 194 | +Please feel free to open pull requests for extending the events standard detailed here as needs arise. |
| 195 | + |
| 196 | +## Drawbacks |
| 197 | + |
| 198 | +There is a known limitation of 16kb strings when capturing logs. |
| 199 | +This can be observed if `token_ids` vary in length across different apps. |
| 200 | +This impacts the amount of events that can be processed. |
0 commit comments