|
| 1 | +# SRC-15: Off-Chain Native Asset Metadata |
| 2 | + |
| 3 | +The following standard attempts to define arbitrary metadata for any [Native Asset](https://docs.fuel.network/docs/sway/blockchain-development/native_assets) that is not required by other contracts onchain, in a stateless manner. Any contract that implements the SRC-15 standard MUST implement the [SRC-20](./src-20-native-asset.md) standard. |
| 4 | + |
| 5 | +## Motivation |
| 6 | + |
| 7 | +The SRC-15 standard seeks to enable data-rich assets on the Fuel Network while maintaining a stateless solution. All metadata queries are done off-chain using the indexer. |
| 8 | + |
| 9 | +## Prior Art |
| 10 | + |
| 11 | +The SRC-7 standard exists prior to the SRC-15 standard and is a stateful solution. The SRC-15 builds off the SRC-7 standard by using the `Metadata` enum however provides a stateless solution. |
| 12 | + |
| 13 | +The use of generic metadata was originally found in the Sway-Lib's [NFT Library](https://github.com/FuelLabs/sway-libs/tree/v0.12.0/libs/nft) which did not use Fuel's [Native Assets](https://docs.fuel.network/docs/sway/blockchain-development/native_assets). This library has since been deprecated. |
| 14 | + |
| 15 | +A previous definition for a metadata standard was written in the original edit of the now defunct [SRC-721](https://github.com/FuelLabs/sway-standards/issues/2). This has since been replaced with the [SRC-20](./src-20-native-asset.md) standard as `SubId` was introduced to enable multiple assets to be minted from a single contract. |
| 16 | + |
| 17 | +## Specification |
| 18 | + |
| 19 | +### Metadata Type |
| 20 | + |
| 21 | +The `Metadata` enum from the SRC-7 standard is also used to represent the metadata in the SRC-15 standard. |
| 22 | + |
| 23 | +### Logging |
| 24 | + |
| 25 | +The following logs MUST be implemented and emitted to follow the SRC-15 standard. Logging MUST be emitted from the contract which minted the asset. |
| 26 | + |
| 27 | +#### SRC15MetadataEvent |
| 28 | + |
| 29 | +The `SRC15MetadataEvent` MUST be emitted at least once for each distinct piece of metadata. The latest emitted `SRC15MetadataEvent` is determined to be the current metadata. |
| 30 | + |
| 31 | +There SHALL be the following fields in the `SRC15MetadataEvent` struct: |
| 32 | + |
| 33 | +* `asset`: The `asset` field SHALL be used for the corresponding `AssetId` for the metadata. |
| 34 | +* `metadata`: The `metadata` field SHALL be used for the corresponding `Metadata` which represents the metadata of the asset. |
| 35 | + |
| 36 | +Example: |
| 37 | + |
| 38 | +```sway |
| 39 | +pub struct SRC15MetadataEvent { |
| 40 | + pub asset: AssetId, |
| 41 | + pub metadata: Metadata, |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +## Rationale |
| 46 | + |
| 47 | +The SRC-15 standard allows for data-rich assets in a stateless manner by associating an asset with some metadata that may later be fetched by the indexer. |
| 48 | + |
| 49 | +## Backwards Compatibility |
| 50 | + |
| 51 | +This standard is compatible with Fuel's [Native Assets](https://docs.fuel.network/docs/sway/blockchain-development/native_assets) and the [SRC-20](./src-20-native-asset.md) standard. This standard is also compatible with the SRC-7 standard which defines a stateful solution. It also maintains compatibility with existing standards in other ecosystems. |
| 52 | + |
| 53 | +## Security Considerations |
| 54 | + |
| 55 | +When indexing for SRC-15 metadata, developers should confirm that the contract that emitted the `SRC15MetadataEvent` is also the contract that minted the asset that the metadata associates with. Additionally, restrictions via access control on who may emit the Metadata should be considered. |
| 56 | + |
| 57 | +## Example Implementation |
| 58 | + |
| 59 | +### Single Native Asset |
| 60 | + |
| 61 | +Example of the SRC-15 implementation where metadata exists for only a single asset with one `SubId`. |
| 62 | + |
| 63 | +```sway |
| 64 | +{{#include ../examples/src15-offchain-metadata/single_asset/src/single_asset.sw}} |
| 65 | +``` |
| 66 | + |
| 67 | +### Multi Native Asset |
| 68 | + |
| 69 | +Example of the SRC-15 implementation where metadata exists for multiple assets with differing `SubId` values. |
| 70 | + |
| 71 | +```sway |
| 72 | +{{#include ../examples/src15-offchain-metadata/multi_asset/src/multi_asset.sw}} |
| 73 | +``` |
0 commit comments