Building NFT auction system with CW721 tokens - custom message handling

I’m developing a smart contract for NFT auctions using CW721 tokens. My setup works like this: when someone owns a CW721 NFT and transfers it to my auction contract, the contract gets a ReceiveNft(cw721::Cw721ReceiveMsg) message that should trigger the auction to begin.

The issue I’m facing is with the message data from Cw721ReceiveMsg. I need to decode the msg field to extract custom auction parameters like:

  • When the auction should start
  • How long it should run
  • What the minimum bid amount is

My current CW721 contract uses standard message handlers. I’m confused about how to modify this so NFT owners can specify their auction settings when they send their tokens.

I attempted to modify the SendNft handler by adding submessages to the response, but I can’t use placeholder values since each token owner needs to set their own auction terms. I’m also questioning if my overall project structure is correct. Right now my CW721 implementation is just a library file with basic cw721 functionality plus metadata support.

You’re on the right track with encoding parameters in the msg field, but double-check that your auction contract validates all incoming data. I hit similar issues building my marketplace contract last year. What worked for me was creating a specific struct for auction parameters, serializing it as JSON, then passing it through Cw721ReceiveMsg. Your auction contract deserializes this in the ReceiveNft handler and validates stuff like start time being future-dated and minimum bid being reasonable. Watch out for msg size limits - keep your parameter struct lean. Also add a fallback for empty or malformed msg fields, maybe default to immediate auction start with standard duration.

Interesting challenge! Quick question though - what happens when multiple people auction the same NFT type at once? Are you doing separate auction instances per token or one big pool?

What placeholders were you trying to use exactly? There might be a workaround that doesn’t mess with the core cw721 handlers.

You mentioned project structure concerns - is your cw721 just a lib right now? You’ll need to decide if you want a separate contract instance or work with existing deployed ones. Depends if you need custom functionality or can stick with standard cw721s.

One more thing - when users transfer their NFT to start an auction, do they lose ownership until it ends? Or are you doing some escrow setup? This’ll affect your message flow between contracts.

What blockchain are you targeting? Some chains have message size limits you’ll need to consider.

you should encode the auction details in the msg field while using send_nft. then, the receiving contract can deserialize it into your custom struct with start time, duration, min bid, etc. better not change the cw721 handlers, just pass your encoded data thru the existing msg.