I’m developing a smart contract for NFT auctions. When users transfer their cw721 tokens to my auction contract, it triggers the ReceiveNft(cw721::Cw721ReceiveMsg) message to begin the auction process.
use cw721::{Cw721ReceiveMsg};
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response};
pub fn handle_receive_token(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: Cw721ReceiveMsg,
) -> Result<Response, ContractError> {
// Need to decode msg.msg to get auction params
let auction_data: AuctionParams = from_binary(&msg.msg)?;
start_new_auction(
deps,
env,
msg.sender,
msg.token_id,
auction_data.end_time,
auction_data.reserve_price,
)
}
The issue I’m facing is that the message data in Cw721ReceiveMsg needs custom decoding to extract auction parameters like end time, reserve price, and other settings. My current NFT contract uses standard message handlers.
I’m struggling with allowing token holders to specify their auction parameters when sending tokens. I attempted modifying the SendNft handler with submsgs but couldn’t figure out how to let users input their own values instead of hardcoded ones.
What’s the best approach to structure this so NFT owners can set custom auction terms?
had this exact issue a few months ago. The fix is in your frontend - you’re probably not serializing the auction params right. make sure your AuctionParams struct has Serialize and Deserialize traits. also double-check that you’re calling to_binary() on the params before stuffing them into the msg field. I bet you’re sending raw JSON instead of proper binary data - super common mistake.
Had the same issue building my NFT marketplace last year. You don’t need to modify the NFT contract handlers - focus on how you build the SendNft message instead. When users want to auction their NFT, they call send_nft on their NFT contract with your auction contract as the recipient. The trick is encoding their auction parameters (reserve price, duration, etc.) as JSON in the msg field. Your auction contract approach with from_binary(&msg.msg) looks right. Just make sure your AuctionParams struct has the right serialization traits and matches what the frontend sends exactly. I added a separate endpoint to validate auction parameters before users actually send their NFTs - saved me tons of headaches. One thing that bit me: validate those decoded parameters properly. Check end times are in the future and reserve prices make sense, or you’ll have issues later in the auction.
This is really interesting! How are you handling the UX side? Like, how do users actually input auction parameters before sending their NFT?
Are you building a frontend form where they fill in reserve price, end time, etc., then your app constructs the SendNft message with encoded params? Or something more direct?
Also wondering about validation timing - do you validate auction parameters right when you receive the NFT, or is there a preview/confirmation step first? If someone sends an NFT with invalid params (like end time in the past), you’d need to return the token gracefully.
One more thing - what happens when someone sends an NFT without proper auction params? Like if they just send it normally without auction data - does your contract reject it or have fallback behavior?
The binary encoding/decoding seems solvable, but the user flow and error handling looks trickier. What’s your experience been?