@@ -266,30 +266,44 @@ public entry fun transfer<T: key>(owner: &signer, object: object::Object<T>, to:
266266Burning / deleting a ` Token ` requires storing a ` BurnRef ` with ` token::generate_burn_ref ` , then calling ` token::burn ` .
267267
268268``` move filename="example.move"
269- use std::option::{Self, Option};
269+ module 0x42::example {
270+ use std::option;
271+ use aptos_token_objects::token::{Self, BurnRef, Token};
272+ use std::string::utf8;
273+ use aptos_framework::object::{Self, Object};
274+
275+ struct CustomData has key, drop {
276+ burn_ref: BurnRef,
277+ }
270278
271- public entry fun mint_token(creator: &signer) {
272- let royalty = option::none();
279+ public entry fun mint_token(creator: &signer) {
273280 let token_constructor_ref = &token::create(
274- creator,
275- "My Collection",
276- "My named Token description",
277- "My named token",
278- royalty ,
279- "https://mycollection.com/my-named-token.jpeg",
281+ creator,
282+ utf8(b "My Collection") ,
283+ utf8(b "My named Token description") ,
284+ utf8(b "My named token") ,
285+ option::none() ,
286+ utf8(b "https://mycollection.com/my-named-token.jpeg") ,
280287 );
288+
289+ let token_signer = &object::generate_signer(token_constructor_ref);
290+
281291 let burn_ref = token::generate_burn_ref(token_constructor_ref);
292+
282293 // Store the burn ref somewhere safe
283- }
294+ move_to(token_signer, CustomData {
295+ burn_ref,
296+ });
297+ }
284298
285- public entry fun burn_token(token: Object<Token>) {
286- // Remove all custom data from the token object.
299+ public entry fun burn_token(token: Object<Token>) acquires CustomData {
287300 let token_address = object::object_address(&token);
288- let CustomData { ... } = move_from<CustomData>(token_address);
289-
301+ // Remove all custom data from the token object.
290302 // Retrieve the burn ref from storage
291- let burn_ref = ...;
303+ let CustomData { burn_ref } = move_from<CustomData>(token_address);
304+ // Burn the token
292305 token::burn(burn_ref);
306+ }
293307}
294308```
295309
@@ -302,22 +316,45 @@ If any custom resources were moved onto the Token, those must be removed / delet
302316Mutating a ` Token ` ’s ` URI ` or ` description ` requires a ` MutatorRef ` (which must be generated when creating the ` Token ` , then stored for later).
303317
304318``` move filename="example.move"
305- use std::option::{Self, Option};
319+ module 0x42::example {
320+ use std::option;
321+ use aptos_token_objects::token::{Self, MutatorRef, Token};
322+ use std::string::utf8;
323+ use aptos_framework::object::{Self, Object};
324+
325+ struct CustomData has key, drop {
326+ mutator_ref: MutatorRef,
327+ }
306328
307- public entry fun mint_token(creator: &signer) {
308- let royalty = option::none();
329+ public entry fun mint_token(creator: &signer) {
309330 // Constructor ref is a non-storable struct returned when creating a new object.
310331 // It can be exchanged for signer to add resources to the token object.
311332 let token_constructor_ref = &token::create(
312- creator,
313- "My Collection",
314- "My named Token description",
315- "My named token" ,
316- royalty ,
317- "https://mycollection.com/my-named-token.jpeg",
333+ creator,
334+ utf8(b "My Collection") ,
335+ utf8(b "My named Token description") ,
336+ utf8(b "My named Token") ,
337+ option::none() ,
338+ utf8(b "https://mycollection.com/my-named-token.jpeg") ,
318339 );
340+
341+ let token_signer = &object::generate_signer(token_constructor_ref);
342+
319343 let mutator_ref = token::generate_mutator_ref(token_constructor_ref);
344+
320345 // Store the mutator ref somewhere safe
346+ move_to(token_signer, CustomData {
347+ mutator_ref,
348+ });
349+ }
350+
351+ public entry fun mutate_token(token: Object<Token>) acquires CustomData {
352+ let token_address = object::object_address(&token);
353+ // Retrieve the mutator ref from storage
354+ let CustomData { mutator_ref } = move_from<CustomData>(token_address);
355+ // Change token description
356+ token::set_description(&mutator_ref, utf8(b"This is my named Token description"));
357+ }
321358}
322359```
323360
0 commit comments