aptos-move/framework/aptos-token-objects/doc/collection.md
<a id="0x4_collection"></a>
0x4::collectionThis defines an object-based Collection. A collection acts as a set organizer for a group of tokens. This includes aspects such as a general description, project URI, name, and may contain other useful generalizations across this set of tokens.
Being built upon objects enables collections to be relatively flexible. As core primitives it supports:
TODO:
CollectionMutatorRefMutationEventMutationFixedSupplyUnlimitedSupplyConcurrentSupplyBurnEventMintEventBurnMintConcurrentBurnEventConcurrentMintEventSetMaxSupplycreate_fixed_collectioncreate_fixed_collection_as_ownercreate_unlimited_collectioncreate_unlimited_collection_as_ownercreate_untracked_collectioncreate_collection_internalenable_ungated_transfercreate_collection_addresscreate_collection_seedincrement_supplydecrement_supplygenerate_mutator_refupgrade_to_concurrentcheck_collection_existsborrowcountcreatordescriptionnameuriborrow_mutset_nameset_descriptionset_uriset_max_supply<a id="0x4_collection_Collection"></a>
CollectionRepresents the common fields for a collection.
<pre><code>#[resource_group_member(#[group = <a href="../../aptos-framework/doc/object.md#0x1_object_ObjectGroup">0x1::object::ObjectGroup</a>])] <b>struct</b> <a href="collection.md#0x4_collection_Collection">Collection</a> <b>has</b> key </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>creator: <b>address</b></code> </dt> <dd> The creator of this collection. </dd> <dt> <code>description: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a></code> </dt> <dd> A brief description of the collection. </dd> <dt> <code>name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a></code> </dt> <dd> An optional categorization of similar token. </dd> <dt> <code>uri: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a></code> </dt> <dd> The Uniform Resource Identifier (uri) pointing to the JSON file stored in off-chain storage; the URL length will likely need a maximum any suggestions? </dd> <dt> <code>mutation_events: <a href="../../aptos-framework/doc/event.md#0x1_event_EventHandle">event::EventHandle</a><<a href="collection.md#0x4_collection_MutationEvent">collection::MutationEvent</a>></code> </dt> <dd> Emitted upon any mutation of the collection. </dd> </dl> </details><a id="0x4_collection_MutatorRef"></a>
MutatorRefThis enables mutating description and URI by higher level services.
<pre><code><b>struct</b> <a href="collection.md#0x4_collection_MutatorRef">MutatorRef</a> <b>has</b> drop, store </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>self: <b>address</b></code> </dt> <dd> </dd> </dl> </details><a id="0x4_collection_MutationEvent"></a>
MutationEventContains the mutated fields name. This makes the life of indexers easier, so that they can directly understand the behavior in a writeset.
<pre><code><b>struct</b> <a href="collection.md#0x4_collection_MutationEvent">MutationEvent</a> <b>has</b> drop, store </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>mutated_field_name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a></code> </dt> <dd> </dd> </dl> </details><a id="0x4_collection_Mutation"></a>
MutationContains the mutated fields name. This makes the life of indexers easier, so that they can directly understand the behavior in a writeset.
<pre><code>#[<a href="../../aptos-framework/doc/event.md#0x1_event">event</a>] <b>struct</b> <a href="collection.md#0x4_collection_Mutation">Mutation</a> <b>has</b> drop, store </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>mutated_field_name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a></code> </dt> <dd> </dd> <dt> <code><a href="collection.md#0x4_collection">collection</a>: <a href="../../aptos-framework/doc/object.md#0x1_object_Object">object::Object</a><<a href="collection.md#0x4_collection_Collection">collection::Collection</a>></code> </dt> <dd> </dd> <dt> <code>old_value: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a></code> </dt> <dd> </dd> <dt> <code>new_value: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a></code> </dt> <dd> </dd> </dl> </details><a id="0x4_collection_FixedSupply"></a>
FixedSupplyFixed supply tracker, this is useful for ensuring that a limited number of tokens are minted. and adding events and supply tracking to a collection.
<pre><code>#[resource_group_member(#[group = <a href="../../aptos-framework/doc/object.md#0x1_object_ObjectGroup">0x1::object::ObjectGroup</a>])] <b>struct</b> <a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a> <b>has</b> key </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>current_supply: u64</code> </dt> <dd> Total minted - total burned </dd> <dt> <code>max_supply: u64</code> </dt> <dd> </dd> <dt> <code>total_minted: u64</code> </dt> <dd> </dd> <dt> <code>burn_events: <a href="../../aptos-framework/doc/event.md#0x1_event_EventHandle">event::EventHandle</a><<a href="collection.md#0x4_collection_BurnEvent">collection::BurnEvent</a>></code> </dt> <dd> Emitted upon burning a Token. </dd> <dt> <code>mint_events: <a href="../../aptos-framework/doc/event.md#0x1_event_EventHandle">event::EventHandle</a><<a href="collection.md#0x4_collection_MintEvent">collection::MintEvent</a>></code> </dt> <dd> Emitted upon minting an Token. </dd> </dl> </details><a id="0x4_collection_UnlimitedSupply"></a>
UnlimitedSupplyUnlimited supply tracker, this is useful for adding events and supply tracking to a collection.
<pre><code>#[resource_group_member(#[group = <a href="../../aptos-framework/doc/object.md#0x1_object_ObjectGroup">0x1::object::ObjectGroup</a>])] <b>struct</b> <a href="collection.md#0x4_collection_UnlimitedSupply">UnlimitedSupply</a> <b>has</b> key </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>current_supply: u64</code> </dt> <dd> </dd> <dt> <code>total_minted: u64</code> </dt> <dd> </dd> <dt> <code>burn_events: <a href="../../aptos-framework/doc/event.md#0x1_event_EventHandle">event::EventHandle</a><<a href="collection.md#0x4_collection_BurnEvent">collection::BurnEvent</a>></code> </dt> <dd> Emitted upon burning a Token. </dd> <dt> <code>mint_events: <a href="../../aptos-framework/doc/event.md#0x1_event_EventHandle">event::EventHandle</a><<a href="collection.md#0x4_collection_MintEvent">collection::MintEvent</a>></code> </dt> <dd> Emitted upon minting an Token. </dd> </dl> </details><a id="0x4_collection_ConcurrentSupply"></a>
ConcurrentSupplySupply tracker, useful for tracking amount of issued tokens. If max_value is not set to U64_MAX, this ensures that a limited number of tokens are minted.
<pre><code>#[resource_group_member(#[group = <a href="../../aptos-framework/doc/object.md#0x1_object_ObjectGroup">0x1::object::ObjectGroup</a>])] <b>struct</b> <a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a> <b>has</b> key </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>current_supply: <a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_Aggregator">aggregator_v2::Aggregator</a><u64></code> </dt> <dd> Total minted - total burned </dd> <dt> <code>total_minted: <a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_Aggregator">aggregator_v2::Aggregator</a><u64></code> </dt> <dd> </dd> </dl> </details><a id="0x4_collection_BurnEvent"></a>
BurnEvent<a id="0x4_collection_MintEvent"></a>
MintEvent<a id="0x4_collection_Burn"></a>
Burn<a id="0x4_collection_Mint"></a>
Mint<a id="0x4_collection_ConcurrentBurnEvent"></a>
ConcurrentBurnEvent<a id="0x4_collection_ConcurrentMintEvent"></a>
ConcurrentMintEvent<a id="0x4_collection_SetMaxSupply"></a>
SetMaxSupply<a id="@Constants_0"></a>
<a id="0x4_collection_MAX_U64"></a>
<pre><code><b>const</b> <a href="collection.md#0x4_collection_MAX_U64">MAX_U64</a>: u64 = 18446744073709551615; </code></pre><a id="0x4_collection_EURI_TOO_LONG"></a>
The URI is over the maximum length
<pre><code><b>const</b> <a href="collection.md#0x4_collection_EURI_TOO_LONG">EURI_TOO_LONG</a>: u64 = 4; </code></pre><a id="0x4_collection_MAX_URI_LENGTH"></a>
<pre><code><b>const</b> <a href="collection.md#0x4_collection_MAX_URI_LENGTH">MAX_URI_LENGTH</a>: u64 = 512; </code></pre><a id="0x4_collection_EALREADY_CONCURRENT"></a>
Tried upgrading collection to concurrent, but collection is already concurrent
<pre><code><b>const</b> <a href="collection.md#0x4_collection_EALREADY_CONCURRENT">EALREADY_CONCURRENT</a>: u64 = 8; </code></pre><a id="0x4_collection_ECOLLECTION_DOES_NOT_EXIST"></a>
The collection does not exist
<pre><code><b>const</b> <a href="collection.md#0x4_collection_ECOLLECTION_DOES_NOT_EXIST">ECOLLECTION_DOES_NOT_EXIST</a>: u64 = 1; </code></pre><a id="0x4_collection_ECOLLECTION_NAME_TOO_LONG"></a>
The collection name is over the maximum length
<pre><code><b>const</b> <a href="collection.md#0x4_collection_ECOLLECTION_NAME_TOO_LONG">ECOLLECTION_NAME_TOO_LONG</a>: u64 = 3; </code></pre><a id="0x4_collection_ECOLLECTION_OWNER_NOT_SUPPORTED"></a>
The collection owner feature is not supported
<pre><code><b>const</b> <a href="collection.md#0x4_collection_ECOLLECTION_OWNER_NOT_SUPPORTED">ECOLLECTION_OWNER_NOT_SUPPORTED</a>: u64 = 11; </code></pre><a id="0x4_collection_ECOLLECTION_SUPPLY_EXCEEDED"></a>
The collection has reached its supply and no more tokens can be minted, unless some are burned
<pre><code><b>const</b> <a href="collection.md#0x4_collection_ECOLLECTION_SUPPLY_EXCEEDED">ECOLLECTION_SUPPLY_EXCEEDED</a>: u64 = 2; </code></pre><a id="0x4_collection_ECONCURRENT_NOT_ENABLED"></a>
Concurrent feature flag is not yet enabled, so the function cannot be performed
<pre><code><b>const</b> <a href="collection.md#0x4_collection_ECONCURRENT_NOT_ENABLED">ECONCURRENT_NOT_ENABLED</a>: u64 = 7; </code></pre><a id="0x4_collection_EDESCRIPTION_TOO_LONG"></a>
The description is over the maximum length
<pre><code><b>const</b> <a href="collection.md#0x4_collection_EDESCRIPTION_TOO_LONG">EDESCRIPTION_TOO_LONG</a>: u64 = 5; </code></pre><a id="0x4_collection_EINVALID_MAX_SUPPLY"></a>
The new max supply cannot be less than the current supply
<pre><code><b>const</b> <a href="collection.md#0x4_collection_EINVALID_MAX_SUPPLY">EINVALID_MAX_SUPPLY</a>: u64 = 9; </code></pre><a id="0x4_collection_EMAX_SUPPLY_CANNOT_BE_ZERO"></a>
The max supply must be positive
<pre><code><b>const</b> <a href="collection.md#0x4_collection_EMAX_SUPPLY_CANNOT_BE_ZERO">EMAX_SUPPLY_CANNOT_BE_ZERO</a>: u64 = 6; </code></pre><a id="0x4_collection_ENO_MAX_SUPPLY_IN_COLLECTION"></a>
The collection does not have a max supply
<pre><code><b>const</b> <a href="collection.md#0x4_collection_ENO_MAX_SUPPLY_IN_COLLECTION">ENO_MAX_SUPPLY_IN_COLLECTION</a>: u64 = 10; </code></pre><a id="0x4_collection_MAX_COLLECTION_NAME_LENGTH"></a>
<pre><code><b>const</b> <a href="collection.md#0x4_collection_MAX_COLLECTION_NAME_LENGTH">MAX_COLLECTION_NAME_LENGTH</a>: u64 = 128; </code></pre><a id="0x4_collection_MAX_DESCRIPTION_LENGTH"></a>
<pre><code><b>const</b> <a href="collection.md#0x4_collection_MAX_DESCRIPTION_LENGTH">MAX_DESCRIPTION_LENGTH</a>: u64 = 2048; </code></pre><a id="0x4_collection_create_fixed_collection"></a>
create_fixed_collectionCreates a fixed-sized collection, or a collection that supports a fixed amount of tokens. This is useful to create a guaranteed, limited supply on-chain digital asset. For example, a collection 1111 vicious vipers. Note, creating restrictions such as upward limits results in data structures that prevent Aptos from parallelizing mints of this collection type. Beyond that, it adds supply tracking with events.
<pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_fixed_collection">create_fixed_collection</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, description: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, max_supply: u64, name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, <a href="royalty.md#0x4_royalty">royalty</a>: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a><<a href="royalty.md#0x4_royalty_Royalty">royalty::Royalty</a>>, uri: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/doc/object.md#0x1_object_ConstructorRef">object::ConstructorRef</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_fixed_collection">create_fixed_collection</a>( creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, description: String, max_supply: u64, name: String, <a href="royalty.md#0x4_royalty">royalty</a>: Option<Royalty>, uri: String, ): ConstructorRef { <b>assert</b>!(max_supply != 0, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="collection.md#0x4_collection_EMAX_SUPPLY_CANNOT_BE_ZERO">EMAX_SUPPLY_CANNOT_BE_ZERO</a>)); <b>let</b> collection_seed = <a href="collection.md#0x4_collection_create_collection_seed">create_collection_seed</a>(&name); <b>let</b> constructor_ref = <a href="../../aptos-framework/doc/object.md#0x1_object_create_named_object">object::create_named_object</a>(creator, collection_seed); <b>let</b> supply = <a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a> { current_supply: <a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_create_aggregator">aggregator_v2::create_aggregator</a>(max_supply), total_minted: <a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_create_unbounded_aggregator">aggregator_v2::create_unbounded_aggregator</a>(), }; <a href="collection.md#0x4_collection_create_collection_internal">create_collection_internal</a>( creator, constructor_ref, description, name, <a href="royalty.md#0x4_royalty">royalty</a>, uri, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(supply), ) } </code></pre> </details><a id="0x4_collection_create_fixed_collection_as_owner"></a>
create_fixed_collection_as_ownerSame functionality as <code>create_fixed_collection</code>, but the caller is the owner of the collection. This means that the caller can transfer the collection to another address. This transfers ownership and minting permissions to the new address.
<pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_fixed_collection_as_owner">create_fixed_collection_as_owner</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, description: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, max_supply: u64, name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, <a href="royalty.md#0x4_royalty">royalty</a>: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a><<a href="royalty.md#0x4_royalty_Royalty">royalty::Royalty</a>>, uri: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/doc/object.md#0x1_object_ConstructorRef">object::ConstructorRef</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_fixed_collection_as_owner">create_fixed_collection_as_owner</a>( creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, description: String, max_supply: u64, name: String, <a href="royalty.md#0x4_royalty">royalty</a>: Option<Royalty>, uri: String, ): ConstructorRef { <b>assert</b>!(<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_is_collection_owner_enabled">features::is_collection_owner_enabled</a>(), <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_unavailable">error::unavailable</a>(<a href="collection.md#0x4_collection_ECOLLECTION_OWNER_NOT_SUPPORTED">ECOLLECTION_OWNER_NOT_SUPPORTED</a>)); <b>let</b> constructor_ref = <a href="collection.md#0x4_collection_create_fixed_collection">create_fixed_collection</a>( creator, description, max_supply, name, <a href="royalty.md#0x4_royalty">royalty</a>, uri, ); <a href="collection.md#0x4_collection_enable_ungated_transfer">enable_ungated_transfer</a>(&constructor_ref); constructor_ref } </code></pre> </details><a id="0x4_collection_create_unlimited_collection"></a>
create_unlimited_collectionCreates an unlimited collection. This has support for supply tracking but does not limit the supply of tokens.
<pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_unlimited_collection">create_unlimited_collection</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, description: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, <a href="royalty.md#0x4_royalty">royalty</a>: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a><<a href="royalty.md#0x4_royalty_Royalty">royalty::Royalty</a>>, uri: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/doc/object.md#0x1_object_ConstructorRef">object::ConstructorRef</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_unlimited_collection">create_unlimited_collection</a>( creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, description: String, name: String, <a href="royalty.md#0x4_royalty">royalty</a>: Option<Royalty>, uri: String, ): ConstructorRef { <b>let</b> collection_seed = <a href="collection.md#0x4_collection_create_collection_seed">create_collection_seed</a>(&name); <b>let</b> constructor_ref = <a href="../../aptos-framework/doc/object.md#0x1_object_create_named_object">object::create_named_object</a>(creator, collection_seed); <b>let</b> supply = <a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a> { current_supply: <a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_create_unbounded_aggregator">aggregator_v2::create_unbounded_aggregator</a>(), total_minted: <a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_create_unbounded_aggregator">aggregator_v2::create_unbounded_aggregator</a>(), }; <a href="collection.md#0x4_collection_create_collection_internal">create_collection_internal</a>( creator, constructor_ref, description, name, <a href="royalty.md#0x4_royalty">royalty</a>, uri, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(supply), ) } </code></pre> </details><a id="0x4_collection_create_unlimited_collection_as_owner"></a>
create_unlimited_collection_as_ownerSame functionality as <code>create_unlimited_collection</code>, but the caller is the owner of the collection. This means that the caller can transfer the collection to another address. This transfers ownership and minting permissions to the new address.
<pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_unlimited_collection_as_owner">create_unlimited_collection_as_owner</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, description: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, <a href="royalty.md#0x4_royalty">royalty</a>: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a><<a href="royalty.md#0x4_royalty_Royalty">royalty::Royalty</a>>, uri: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/doc/object.md#0x1_object_ConstructorRef">object::ConstructorRef</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_unlimited_collection_as_owner">create_unlimited_collection_as_owner</a>( creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, description: String, name: String, <a href="royalty.md#0x4_royalty">royalty</a>: Option<Royalty>, uri: String, ): ConstructorRef { <b>assert</b>!(<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_is_collection_owner_enabled">features::is_collection_owner_enabled</a>(), <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_unavailable">error::unavailable</a>(<a href="collection.md#0x4_collection_ECOLLECTION_OWNER_NOT_SUPPORTED">ECOLLECTION_OWNER_NOT_SUPPORTED</a>)); <b>let</b> constructor_ref = <a href="collection.md#0x4_collection_create_unlimited_collection">create_unlimited_collection</a>( creator, description, name, <a href="royalty.md#0x4_royalty">royalty</a>, uri, ); <a href="collection.md#0x4_collection_enable_ungated_transfer">enable_ungated_transfer</a>(&constructor_ref); constructor_ref } </code></pre> </details><a id="0x4_collection_create_untracked_collection"></a>
create_untracked_collectionCreates an untracked collection, or a collection that supports an arbitrary amount of tokens. This is useful for mass airdrops that fully leverage Aptos parallelization. TODO: Hide this until we bring back meaningful way to enforce burns
<pre><code><b>fun</b> <a href="collection.md#0x4_collection_create_untracked_collection">create_untracked_collection</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, description: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, <a href="royalty.md#0x4_royalty">royalty</a>: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a><<a href="royalty.md#0x4_royalty_Royalty">royalty::Royalty</a>>, uri: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/doc/object.md#0x1_object_ConstructorRef">object::ConstructorRef</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="collection.md#0x4_collection_create_untracked_collection">create_untracked_collection</a>( creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, description: String, name: String, <a href="royalty.md#0x4_royalty">royalty</a>: Option<Royalty>, uri: String, ): ConstructorRef { <b>let</b> collection_seed = <a href="collection.md#0x4_collection_create_collection_seed">create_collection_seed</a>(&name); <b>let</b> constructor_ref = <a href="../../aptos-framework/doc/object.md#0x1_object_create_named_object">object::create_named_object</a>(creator, collection_seed); <a href="collection.md#0x4_collection_create_collection_internal">create_collection_internal</a><<a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a>>( creator, constructor_ref, description, name, <a href="royalty.md#0x4_royalty">royalty</a>, uri, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_none">option::none</a>(), ) } </code></pre> </details><a id="0x4_collection_create_collection_internal"></a>
create_collection_internal<a id="0x4_collection_enable_ungated_transfer"></a>
enable_ungated_transfer<a id="0x4_collection_create_collection_address"></a>
create_collection_addressGenerates the collections address based upon the creators address and the collection's name
<pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_collection_address">create_collection_address</a>(creator: &<b>address</b>, name: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <b>address</b> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_collection_address">create_collection_address</a>(creator: &<b>address</b>, name: &String): <b>address</b> { <a href="../../aptos-framework/doc/object.md#0x1_object_create_object_address">object::create_object_address</a>(creator, <a href="collection.md#0x4_collection_create_collection_seed">create_collection_seed</a>(name)) } </code></pre> </details><a id="0x4_collection_create_collection_seed"></a>
create_collection_seedNamed objects are derived from a seed, the collection's seed is its name.
<pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_collection_seed">create_collection_seed</a>(name: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_create_collection_seed">create_collection_seed</a>(name: &String): <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8> { <b>assert</b>!(name.length() <= <a href="collection.md#0x4_collection_MAX_COLLECTION_NAME_LENGTH">MAX_COLLECTION_NAME_LENGTH</a>, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_out_of_range">error::out_of_range</a>(<a href="collection.md#0x4_collection_ECOLLECTION_NAME_TOO_LONG">ECOLLECTION_NAME_TOO_LONG</a>)); *name.bytes() } </code></pre> </details><a id="0x4_collection_increment_supply"></a>
increment_supplyCalled by token on mint to increment supply if there's an appropriate Supply struct.
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="collection.md#0x4_collection_increment_supply">increment_supply</a>(<a href="collection.md#0x4_collection">collection</a>: &<a href="../../aptos-framework/doc/object.md#0x1_object_Object">object::Object</a><<a href="collection.md#0x4_collection_Collection">collection::Collection</a>>, <a href="token.md#0x4_token">token</a>: <b>address</b>): <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a><<a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_AggregatorSnapshot">aggregator_v2::AggregatorSnapshot</a><u64>> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>friend</b> <b>fun</b> <a href="collection.md#0x4_collection_increment_supply">increment_supply</a>( <a href="collection.md#0x4_collection">collection</a>: &Object<<a href="collection.md#0x4_collection_Collection">Collection</a>>, <a href="token.md#0x4_token">token</a>: <b>address</b>, ): Option<AggregatorSnapshot<u64>> <b>acquires</b> <a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a>, <a href="collection.md#0x4_collection_UnlimitedSupply">UnlimitedSupply</a>, <a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a> { <b>let</b> collection_addr = <a href="collection.md#0x4_collection">collection</a>.object_address(); <b>if</b> (<b>exists</b><<a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a>>(collection_addr)) { <b>let</b> supply = &<b>mut</b> <a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a>[collection_addr]; <b>assert</b>!( supply.current_supply.try_add(1), <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_out_of_range">error::out_of_range</a>(<a href="collection.md#0x4_collection_ECOLLECTION_SUPPLY_EXCEEDED">ECOLLECTION_SUPPLY_EXCEEDED</a>), ); supply.total_minted.add(1); <a href="../../aptos-framework/doc/event.md#0x1_event_emit">event::emit</a>( <a href="collection.md#0x4_collection_Mint">Mint</a> { <a href="collection.md#0x4_collection">collection</a>: collection_addr, index: supply.total_minted.snapshot(), <a href="token.md#0x4_token">token</a>, }, ); <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(supply.total_minted.snapshot()) } <b>else</b> <b>if</b> (<b>exists</b><<a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a>>(collection_addr)) { <b>let</b> supply = &<b>mut</b> <a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a>[collection_addr]; supply.current_supply += 1; supply.total_minted += 1; <b>assert</b>!( supply.current_supply <= supply.max_supply, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_out_of_range">error::out_of_range</a>(<a href="collection.md#0x4_collection_ECOLLECTION_SUPPLY_EXCEEDED">ECOLLECTION_SUPPLY_EXCEEDED</a>), ); <a href="../../aptos-framework/doc/event.md#0x1_event_emit">event::emit</a>( <a href="collection.md#0x4_collection_Mint">Mint</a> { <a href="collection.md#0x4_collection">collection</a>: collection_addr, index: <a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_create_snapshot">aggregator_v2::create_snapshot</a>(supply.total_minted), <a href="token.md#0x4_token">token</a>, }, ); <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(<a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_create_snapshot">aggregator_v2::create_snapshot</a><u64>(supply.total_minted)) } <b>else</b> <b>if</b> (<b>exists</b><<a href="collection.md#0x4_collection_UnlimitedSupply">UnlimitedSupply</a>>(collection_addr)) { <b>let</b> supply = &<b>mut</b> <a href="collection.md#0x4_collection_UnlimitedSupply">UnlimitedSupply</a>[collection_addr]; supply.current_supply += 1; supply.total_minted += 1; <a href="../../aptos-framework/doc/event.md#0x1_event_emit">event::emit</a>( <a href="collection.md#0x4_collection_Mint">Mint</a> { <a href="collection.md#0x4_collection">collection</a>: collection_addr, index: <a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_create_snapshot">aggregator_v2::create_snapshot</a>(supply.total_minted), <a href="token.md#0x4_token">token</a>, }, ); <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(<a href="../../aptos-framework/doc/aggregator_v2.md#0x1_aggregator_v2_create_snapshot">aggregator_v2::create_snapshot</a><u64>(supply.total_minted)) } <b>else</b> { <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_none">option::none</a>() } } </code></pre> </details><a id="0x4_collection_decrement_supply"></a>
decrement_supplyCalled by token on burn to decrement supply if there's an appropriate Supply struct.
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="collection.md#0x4_collection_decrement_supply">decrement_supply</a>(<a href="collection.md#0x4_collection">collection</a>: &<a href="../../aptos-framework/doc/object.md#0x1_object_Object">object::Object</a><<a href="collection.md#0x4_collection_Collection">collection::Collection</a>>, <a href="token.md#0x4_token">token</a>: <b>address</b>, index: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a><u64>, previous_owner: <b>address</b>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>friend</b> <b>fun</b> <a href="collection.md#0x4_collection_decrement_supply">decrement_supply</a>( <a href="collection.md#0x4_collection">collection</a>: &Object<<a href="collection.md#0x4_collection_Collection">Collection</a>>, <a href="token.md#0x4_token">token</a>: <b>address</b>, index: Option<u64>, previous_owner: <b>address</b>, ) <b>acquires</b> <a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a>, <a href="collection.md#0x4_collection_UnlimitedSupply">UnlimitedSupply</a>, <a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a> { <b>let</b> collection_addr = <a href="collection.md#0x4_collection">collection</a>.object_address(); <b>if</b> (<b>exists</b><<a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a>>(collection_addr)) { <b>let</b> supply = &<b>mut</b> <a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a>[collection_addr]; supply.current_supply.sub(1); <a href="../../aptos-framework/doc/event.md#0x1_event_emit">event::emit</a>( <a href="collection.md#0x4_collection_Burn">Burn</a> { <a href="collection.md#0x4_collection">collection</a>: collection_addr, index: *index.<a href="collection.md#0x4_collection_borrow">borrow</a>(), <a href="token.md#0x4_token">token</a>, previous_owner, }, ); } <b>else</b> <b>if</b> (<b>exists</b><<a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a>>(collection_addr)) { <b>let</b> supply = &<b>mut</b> <a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a>[collection_addr]; supply.current_supply -= 1; <a href="../../aptos-framework/doc/event.md#0x1_event_emit">event::emit</a>( <a href="collection.md#0x4_collection_Burn">Burn</a> { <a href="collection.md#0x4_collection">collection</a>: collection_addr, index: *index.<a href="collection.md#0x4_collection_borrow">borrow</a>(), <a href="token.md#0x4_token">token</a>, previous_owner, }, ); } <b>else</b> <b>if</b> (<b>exists</b><<a href="collection.md#0x4_collection_UnlimitedSupply">UnlimitedSupply</a>>(collection_addr)) { <b>let</b> supply = &<b>mut</b> <a href="collection.md#0x4_collection_UnlimitedSupply">UnlimitedSupply</a>[collection_addr]; supply.current_supply -= 1; <a href="../../aptos-framework/doc/event.md#0x1_event_emit">event::emit</a>( <a href="collection.md#0x4_collection_Burn">Burn</a> { <a href="collection.md#0x4_collection">collection</a>: collection_addr, index: *index.<a href="collection.md#0x4_collection_borrow">borrow</a>(), <a href="token.md#0x4_token">token</a>, previous_owner, }, ); } } </code></pre> </details><a id="0x4_collection_generate_mutator_ref"></a>
generate_mutator_refCreates a MutatorRef, which gates the ability to mutate any fields that support mutation.
<pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_generate_mutator_ref">generate_mutator_ref</a>(ref: &<a href="../../aptos-framework/doc/object.md#0x1_object_ConstructorRef">object::ConstructorRef</a>): <a href="collection.md#0x4_collection_MutatorRef">collection::MutatorRef</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_generate_mutator_ref">generate_mutator_ref</a>(ref: &ConstructorRef): <a href="collection.md#0x4_collection_MutatorRef">MutatorRef</a> { <b>let</b> <a href="../../aptos-framework/doc/object.md#0x1_object">object</a> = ref.object_from_constructor_ref<<a href="collection.md#0x4_collection_Collection">Collection</a>>(); <a href="collection.md#0x4_collection_MutatorRef">MutatorRef</a> { self: <a href="../../aptos-framework/doc/object.md#0x1_object">object</a>.object_address() } } </code></pre> </details><a id="0x4_collection_upgrade_to_concurrent"></a>
upgrade_to_concurrent<a id="0x4_collection_check_collection_exists"></a>
check_collection_exists<a id="0x4_collection_borrow"></a>
borrow<a id="0x4_collection_count"></a>
countProvides the count of the current selection if supply tracking is used
Note: Calling this method from transaction that also mints/burns, prevents it from being parallelized.
<pre><code>#[view] <b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_count">count</a><T: key>(<a href="collection.md#0x4_collection">collection</a>: <a href="../../aptos-framework/doc/object.md#0x1_object_Object">object::Object</a><T>): <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a><u64> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_count">count</a><T: key>( <a href="collection.md#0x4_collection">collection</a>: Object<T> ): Option<u64> <b>acquires</b> <a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a>, <a href="collection.md#0x4_collection_UnlimitedSupply">UnlimitedSupply</a>, <a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a> { <b>let</b> collection_address = <a href="collection.md#0x4_collection">collection</a>.object_address(); <a href="collection.md#0x4_collection_check_collection_exists">check_collection_exists</a>(collection_address); <b>if</b> (<b>exists</b><<a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a>>(collection_address)) { <b>let</b> supply = &<a href="collection.md#0x4_collection_ConcurrentSupply">ConcurrentSupply</a>[collection_address]; <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(supply.current_supply.read()) } <b>else</b> <b>if</b> (<b>exists</b><<a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a>>(collection_address)) { <b>let</b> supply = &<a href="collection.md#0x4_collection_FixedSupply">FixedSupply</a>[collection_address]; <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(supply.current_supply) } <b>else</b> <b>if</b> (<b>exists</b><<a href="collection.md#0x4_collection_UnlimitedSupply">UnlimitedSupply</a>>(collection_address)) { <b>let</b> supply = &<a href="collection.md#0x4_collection_UnlimitedSupply">UnlimitedSupply</a>[collection_address]; <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(supply.current_supply) } <b>else</b> { <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_none">option::none</a>() } } </code></pre> </details><a id="0x4_collection_creator"></a>
creator<a id="0x4_collection_description"></a>
description<a id="0x4_collection_name"></a>
name<a id="0x4_collection_uri"></a>
uri<a id="0x4_collection_borrow_mut"></a>
borrow_mut<a id="0x4_collection_set_name"></a>
set_nameCallers of this function must be aware that changing the name will change the calculated collection's address when calling <code>create_collection_address</code>. Once the collection has been created, the collection address should be saved for reference and <code>create_collection_address</code> should not be used to derive the collection's address.
After changing the collection's name, to create tokens - only call functions that accept the collection object as an argument.
<pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_set_name">set_name</a>(mutator_ref: &<a href="collection.md#0x4_collection_MutatorRef">collection::MutatorRef</a>, name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="collection.md#0x4_collection_set_name">set_name</a>(mutator_ref: &<a href="collection.md#0x4_collection_MutatorRef">MutatorRef</a>, name: String) <b>acquires</b> <a href="collection.md#0x4_collection_Collection">Collection</a> { <b>assert</b>!(name.length() <= <a href="collection.md#0x4_collection_MAX_COLLECTION_NAME_LENGTH">MAX_COLLECTION_NAME_LENGTH</a>, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_out_of_range">error::out_of_range</a>(<a href="collection.md#0x4_collection_ECOLLECTION_NAME_TOO_LONG">ECOLLECTION_NAME_TOO_LONG</a>)); <b>let</b> <a href="collection.md#0x4_collection">collection</a> = <a href="collection.md#0x4_collection_borrow_mut">borrow_mut</a>(mutator_ref); <a href="../../aptos-framework/doc/event.md#0x1_event_emit">event::emit</a>(<a href="collection.md#0x4_collection_Mutation">Mutation</a> { mutated_field_name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"name") , <a href="collection.md#0x4_collection">collection</a>: <a href="../../aptos-framework/doc/object.md#0x1_object_address_to_object">object::address_to_object</a>(mutator_ref.self), old_value: <a href="collection.md#0x4_collection">collection</a>.name, new_value: name, }); <a href="collection.md#0x4_collection">collection</a>.name = name; } </code></pre> </details><a id="0x4_collection_set_description"></a>
set_description<a id="0x4_collection_set_uri"></a>
set_uri<a id="0x4_collection_set_max_supply"></a>
set_max_supply<a id="@Specification_1"></a>
<a id="@Specification_1_increment_supply"></a>
increment_supply