How to create NFT tokens from external CosmWasm contract

I’m trying to create an NFT token by calling another CosmWasm smart contract but running into issues. Here’s my current approach:

let token_metadata = TokenMetadata {
    image: None,
    image_data: None,
    external_url: None,
    description: None,
    name: None,
    attributes: None,
    background_color: None,
    animation_url: None,
    youtube_url: None,
};

let create_token_msg = CreateTokenMsg {
    token_id: "456".to_string(),
    owner: info.sender.to_string(),
    token_uri: None,
    extension: token_metadata.clone(),
};

let execute_msg = ExecuteMsg::CreateToken(create_token_msg.clone());

let response = wasm_execute(
    state.nft_contract_addr.ok_or(ContractError::MissingNftContract {})?,
    &execute_msg,
    vec![],
)?;

The code compiles fine but doesn’t work as expected. The NFT contract I’m calling was built from standard examples. I suspect I’m missing something small but can’t figure out what.

Also, what’s the proper way to invoke queries and entry points from different contracts in CosmWasm?

check if your nft contract address is good in state. I once left it empty and got super weird errors. plus, both contracts should use the same cw721 versions. mismatched versions can fail silently even if the code compiles perfectly.

Your wasm_execute call isn’t working because you’re not adding the message to your response. You can’t just call wasm_execute and return - you need to include that message in your contract’s response:

let msg = wasm_execute(
    state.nft_contract_addr.ok_or(ContractError::MissingNftContract {})?,
    &execute_msg,
    vec![],
)?;

Ok(Response::new()
    .add_message(msg)
    .add_attribute("action", "create_nft_token"))

For cross-contract queries, use deps.querier.query_wasm_smart() for smart queries or deps.querier.query_wasm_raw() for raw state queries. Just make sure the target contract’s query messages are defined in your calling contract’s dependencies.

I’ve hit this exact issue before - forgot to add the execute message to the response, so the cross-contract call never actually fired.

Oh cool, I’ve been working with CosmWasm cross-contract calls lately too! What error messages are you getting exactly? Does the transaction fail completely or succeed without minting the NFT?

Also, what’s your NFT contract setup like? You mentioned “standard examples” - are you using cw721-base or your own implementation? The ExecuteMsg variants can differ between versions.

I noticed you’re cloning create_token_msg when passing it to ExecuteMsg::CreateToken(). Won’t cause issues, but is that intentional or leftover from debugging?

LiamDragon22’s right about adding the message to your response. I’m also curious about your contract’s entry point structure. Are you handling this properly in the execute function? Sometimes the surrounding code reveals other issues.

Have you tested the NFT contract directly (without the cross-contract call) to make sure it works by itself first?