Sui.

Post

Share your knowledge.

Owen.
Owen486
Jun 11, 2025
Expert Q&A

How to update a merchant's key in ObjectTable when it changes in the struct?

Hi everyone, I'm just getting started with writing smart contracts and I'm working on my very first project. I'd love some help with an issue I'm stuck on.

So far, I’ve created a Merchant struct that looks like this:

  • id: a unique identifier (UID)
  • owner: the address of the merchant
  • key: a String used as a unique key
  • balance: a u64 representing their balance

I also made a MerchantRegistry struct to manage all merchants:

  • id: another UID
  • merchant_to_address: an ObjectTable<address, Merchant> mapping addresses to merchants
  • merchant_to_key: an ObjectTable<String, Merchant> mapping keys to merchants

I want to be able to look up a merchant either by their address or by their key.

When a user updates their key inside the Merchant struct, the change doesn’t automatically update the key in the merchant_to_key table. That means the old key still points to the merchant, which breaks things.

I tried removing the entry from the table and inserting it back with the new key, but I keep running into errors like:

"Cannot ignore values without drop ability"

I'm pretty sure this is a beginner mistake, but I haven't been able to find a clear explanation or solution anywhere. Is there a proper way to handle updating the key in both the struct and the lookup table?

  • Sui
  • Move
5
0
Share
Comments
.

Do you know the answer?

Please log in and share it.

Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.

367Posts503Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

Gain Reputation Points & Get Rewards for Helping the Sui Community Grow.

Reward CampaignJuly