Modifying Mutable Attributes on WAX NFTs

When I left off the last time, I had just finished creating the basic functionality for consuming potions to gain health. Now I’m moving on to modifying mutable attributes on tokens on the WAX Blockchain.

What are Mutable Attributes?

NFTs on the WAX Blockchain have two different types of data associated with them: Immutable Data, and Mutable Data. Immutable data is set when the NFT is created, and can NOT be changed after the NFT is minted, making these data points a permeant and unchangeable data property. This is useful for things like the token name, image, etc.

viewing immutable and mutable data
Viewing the Immutable and Mutable Attributes associated with a Character NFT.

Mutable Data on the other hand, is set after the NFT is minted, and can be modified through API calls to the blockchain. The owner of the collection can execute these calls to set mutable data regardless of what wallet they reside in, and without the authority of the user that holds the NFT. I’ll be using this mutable data to keep track of the player character’s Level and Experience Points.

Modifying mutable attributes: Make it Work!

I’m going to start on the backend, working on the API route to accept parameters for the Character’s NFT ID and the Enemy’s NFT ID.

getting ready to being modifying mutable attributes
Getting the required IDs, then looking up the appropriate information for each

After getting the IDs, I’ll search for the Character in the Database, then search the blockchain for the Enemy. Each Enemy NFT has an immutable data field for XP with an integer value, and once I have my enemy and character objects, I’ll pull the XP given by the enemy from the object and add it to the existing Experience Points the character has gained.

const experienceGained = + character.experiencePoints;

Create the Action

Now I have to build the action for the transaction. As I said in previous updates, this is going to look pretty familiar, but now we’re sending in a new data point: new_mutable_data

creating the action to begin modifying mutable attributes
Preparing the transaction action.

The new_mutable_data expects the data as you can see in the action. The property will be defined by specifying the “key” and then “value” and in the case of our action will be modifying the character’s “level” and “experiencePoints” properties. Mutable data can and will be overwritten each time this API is called, and you want to make sure that all data points are set to avoid null value problems. I’m only modifying the experiencePoints value, but I’m passing the current Character’s Level into the Level value so that it remains after the update.

All that is left to do is to push the transaction, modifying mutable attributes! I’ve shown this a few times now, but here it is again:

sending the transaction for modifying mutable attributes
Sending the transaction

Now I can go to the NFT to see what I’ve done! I prefer viewing this kind of information on but you can view it most places.

viewing the modified mutable attributes
Viewing the NFT’s history on AtomicHub

As you can see from the blockchain, a full history of the character’s activities will be saved. Each time this function runs, a new line like you see above will be added to the record. Old Data an New Data are visible, but only the new data will be set to the token. Here’s how it looks again when simply viewing the NFT:

viewing NFT immutable and mutable data

Wrapping Up

Modifying mutable attributes is another big milestone update, but there’s still work to be done here. I need to add logic for leveling up the character and add this call to the battle rewards logic to give the characters experience after the enemy is defeated. I’m going to be spending my time doing that and testing and squashing bugs along the way. Most of my required functionality is now built, so things might get a little quiet for game updates for a few weeks, but I’ll be sure to post about anything interesting along the way!

Leave a Reply

Your email address will not be published. Required fields are marked *