2.2.1 • Published 3 years ago

@animoca/f1dt-core_metadata v2.2.1

Weekly downloads
64
License
MIT
Repository
github
Last release
3 years ago

F1 Delta Time, Core Metadata library

Core metadata

Core attributes

An F1 Delta Time NFT comes with a number of core attributes embedded within the value of the token identifier. These attributes comprise what we call the token's Core Metadata. There are two main benefits for using this structure: 1. the core attributes are set at creation and forever immutable, 2. the tokens can be interpreted on-chain. For example, a contract could provide a service in exchange for a token but only if this token is a Car with a rarity between 7 and 9.

Here is the current list of the core attributes:

Attribute NameBinary PositionData TypeRequiredSeason SpecificCollection IdentifierDescription
nonFungibleFlag255bitnonoyesUsed to distinguish fungible and non-fungible tokens. A value of 1 represents a non-fungible token.
padding1248uint7noN/AyesReserved for later use.
typeId240uint8yesnoyesNumerical representation of the type of the token, for example Car, Driver or Gears.
subTypeId232uint8noyesyesNumerical representation of the subType of the token, when applicable. For example Gears have different possible subTypes such as Helmet or Gloves.
seasonId224uint8yesnoyesNumerical representation of the season of the token, for example 2019.
padding2212uint32noN/AnoReserved for later use.
trackId200uint8noyesnoNumerical representation of the track of the token, for example Circuit de Monaco.
modelId192uint8noyesnoNumerical representation of the model of the token, for example Satsuma.
teamId184uint8noyesnoNumerical representation of the team of the token, for example Alfa Romeo Racing.
rarity176uint8yesnonoThe rarity level of the token.
countryId168uint8noyesnoNumerical representation of the country of the token, for example Monaco.
labelId152uint16nononoNumerical representation of label of the token. Label are used for specific tokens and is intended to be used for collection and gamfication.
driverId136uint16nononoThe driver number for a Driver.
stat1120uint16noyesnoThe Top Speed of a Car/Part/Tyre or the Stamina of a Driver/Gear.
stat2104uint16noyesnoThe Acceleration of a Car/Part/Tyre or the Aggression of a Driver/Gear.
stat388uint16noyesnoThe Grip of a Car/Part/Tyre or the Concentration of a Driver/Gear.
luck72uint16noyesnoThe luck of the token.
effect64uint8noyesnoThe effect of the token.
special156uint8noyesnoThe first special of the token.
special248uint8noyesnoThe second special of the token.
counter0uint48noyesnoField used to ensure unicity of the tokens in case 2 tokens would have exactly the same other attributes.

Required indicates whether the attribute must have a value different from zero.

Season Specific indicates whether the attribute's interpretation can vary between seasons.

Collection Identifier indicates whether the attribute is part of the collection identifier. Collection identifiers are primarily composed of the typeId, subTypeId and seasonId. For example Car 2019 or Intermediate Tyres 2020.

Some attributes may or may not be needed, depending on the type, subType and season of the token (refer to the season-specific mapping files for more details).

Mapped core attributes

Core attributes are encoded as numerical values. Those which name ends with Id are unmapped and can be mapped to their text value using the mappings contained in this library. For example, typeId 1 can be mapped to the text value Car.

Library usage

module.metadata object

A set of functions which help with the manipulation of token identifiers and metadata objects.

coreMetadataFromId(id) and fullMetadataFromId(id, [network]) functions

Build metadata objects from token identifiers.

const { coreMetadataFromId, fullMetadataFromId } = require('@animoca/f1dt-core_metadata').utils;

const tokenId = '57897811519642769433138067471762254623735906850517137802921006713614358282351'; // the 1-1-1
const coreMetadata = coreMetadataFromId(tokenId);
console.log(coreMetadata);
const fullMetadata = fullMetadataFromId(tokenId);
console.log(fullMetadata);

idFromCoreMetadata(coreMetadata) function

Build token identifiers from core attributes (mapped and/or unmapped).

const { idFromCoreMetadata } = require('@animoca/f1dt-core_metadata').utils;
const tokenId1 = idFromCoreMetadata({
    typeId: '1', // Car
    subTypeId: '0',
    seasonId: '2', // 2019
});
const tokenId2 = idFromCoreMetadata({
    typeId: '1', // Car
    subTypeId: '0',
    season: '2019',
});
const tokenId3 = idFromCoreMetadata({
    type: 'Car',
    subTypeId: 'None',
    seasonId: '2019',
});
console.log(tokenId1, tokenId2, tokenId3);
// tokenId1 == tokenId2 == tokenId3

module.constants object

Some project constants such as the bits layout object and the fixed number of bits in the collection identifiers.

module.mappings object

All the mappings necessary to manipulate metadata divided in common mappings and season-specific mappings.

Retrieve the name of a team from its id for season 2019:

const seasonMappings = require('@animoca/f1dt-core_metadata').mappings['2019'];

Retrieve the Tier for a rarity:

module.collections object

The lists of existing collections.

Scripts

Generate metadata from a token identifier

node scripts/metadataFromId.js -i <id> -n <network> [--full]
2.2.1

3 years ago

2.1.0

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.1

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago