Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to Collection and TokenMetadata: Derive attributes #48

Merged
merged 7 commits into from
Sep 14, 2022

Conversation

vickygos
Copy link
Contributor

@vickygos vickygos commented Sep 14, 2022

  • In Collection, make init field attributes_frequency_counts optional and if not provided, we fill derive frequency from the collection's tokens' metadata.
  • Added a helper method to TokenMetadata to more easily construct metadata, e.g. instead of having to:
# Original way:
TokenMetadata(
      string_attributes={
          "hat": StringAttribute(name="hat", value="blue"),
          "shirt": StringAttribute(name="shirt", value="red"),
      },
      numeric_attributes={
          "level": NumericAttribute(name="level", value=1),
      },
  ),

New optional way:

TokenMetadata.from_attributes(
      {
          "hat": "blue",
          "shirt": "red",
          "level": 1,
      }
  )
  • Additionally, added another factory method for Token:
    Before:
Token(
    token_identifier=EVMContractTokenIdentifier(
        contract_address="0xa3049...", token_id=1
    ),
    token_standard=TokenStandard.ERC721,
    metadata=TokenMetadata(
        string_attributes={
            "hat": StringAttribute(name="hat", value="cap"),
            "shirt": StringAttribute(name="shirt", value="blue"),
        }
    )

Now you can do:

Token.from_erc721(
    contract_address="0xa3049...",
    token_id=1,
    metadata_dict={"hat": "cap", "shirt": "blue"},
)

@vickygos vickygos merged commit ceb2f0c into main Sep 14, 2022
@vickygos vickygos deleted the make_collection_attributes_dist_optional branch September 14, 2022 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants