I’m trying to build an auction smart contract that works with cw721 NFTs. The basic flow is that NFT holders transfer their tokens to my auction contract, which triggers the ReceiveNft(cw721::Cw721ReceiveMsg) message and starts the auction process.
The issue I’m facing is with the message data in Cw721ReceiveMsg. I need to decode this message to extract custom auction parameters like auction duration, starting price, and begin time. However, my current cw721 contract uses standard message handlers and I can’t figure out how to modify it so users can include their auction settings when sending tokens.
I attempted to modify the SendNft handler by adding submessages to the response, but I can’t hardcode auction values since each user needs to specify their own parameters. I’m also questioning my overall architecture approach. Right now my cw721 contract is just a basic library implementation with metadata support.
What’s the best way to structure this so token owners can specify auction parameters when transferring their NFTs?
Hey @Kai29! Your project sounds really interesting. I’ve been messing around with cw721 stuff lately and hit similar issues.
Just want to confirm your setup - users call send_nft directly from the cw721 contract to transfer to your auction contract? If so, the msg field in Cw721ReceiveMsg should definitely let you pack custom data.
When someone calls send_nft(contract, token_id, msg), that msg parameter gets passed to your auction contract’s ReceiveNft handler. You could serialize your auction params (duration, starting price, etc) into that msg field as JSON or binary.
What’s your current ReceiveNft implementation look like? Are you already trying to deserialize the msg field?
Also curious about the user flow - how do users interact with this? Through a frontend that builds the message, or do they manually craft auction parameters?
Code snippets would help since there might be a simpler solution depending on how you’re structuring the message types.
Your architecture looks solid. I built something similar last year and sticking with the cw721 standard was definitely the right move. Use the msg field in Cw721ReceiveMsg - that’s exactly what it’s for. Don’t use JSON strings for your auction parameters though. Create a custom AuctionParams struct with duration, starting_price, and begin_time fields, then serialize to binary when calling send_nft. You’ll get better type safety and smaller messages. Here’s what bit me: validate everything in your ReceiveNft handler before creating auctions. Users will send garbage like negative prices or invalid durations. Also handle deserialization failures gracefully - return the NFT to the sender instead of just throwing an error. Frontends handle the parameter encoding nicely, but manual interaction works fine too once you document the binary format.
you dont need to touch the cw721 contract. just base64 encode your auction params as json and stick them in the msg field when you call send_nft. ive used this approach before - works great. decode it in your ReceiveNft handler and pull out duration, price, whatever you need. much easier than dealing with submessages.