public-awesome / cw-nfts

Examples and helpers to build NFT contracts on CosmWasm
Apache License 2.0
189 stars 181 forks source link

How to make a Querier #63

Closed arlicle closed 2 years ago

arlicle commented 2 years ago

I want query cw721-base contract on other contract, It's need a arg querier, How can I make a querier?

    pub fn query<T: DeserializeOwned>(
        &self,
        querier: &QuerierWrapper,
        req: QueryMsg,
    ) -> StdResult<T> {
        let query = WasmQuery::Smart {
            contract_addr: self.addr().into(),
            msg: to_binary(&req)?,
        }
        .into();
        querier.query(&query)
    }
JakeHartnell commented 2 years ago

Please ask CosmWasm programming questions in the main CosmWasm discord: https://discord.gg/Hzpfq9rD

If you're trying to query in an execute or query method with access to Deps, would look something like so:

let resp: NumTokensResponse = deps.querier.query_wasm_smart(
                        &cw721_contract_address,
                        &Cw721QueryMsg::NumTokens {},
                    )?;