1

I'm using CosmWasm and CW-Asset crates, and I want to check the smart contract Address balance for a specific cw20 token balance on the current smart contract address before transferring the tokens to another persons address. I have Deps/DepsMut, API and MessageInfo available to me in the executing message. How do I get the address of the currently running smart contract (without passing it in on the InstantiateMsg)? I have not yet seen a way to do this.

https://docs.rs/cw-asset/1.0.0/cw_asset/type.AssetInfo.html#method.query_balance

petegordon
  • 339
  • 1
  • 9
  • 1
    May have found the answer Env.ContractInfo.CanonicalAddr ... now just to figure out how to test it... (hadn't used Env previously)... https://docs.rs/cosmwasm-std/0.9.2/cosmwasm_std/struct.Env.html – petegordon Mar 19 '22 at 17:41

1 Answers1

0

The answer is use Env.ContractInfo.CanonicalAddress

https://docs.rs/cosmwasm-std/0.9.2/cosmwasm_std/struct.Env.html

If you are running cosmwasm unit tests, you can use mock_env() and the default value is "cosmos2contract". https://github.com/CosmWasm/cosmwasm/blob/6a447c7dc90f8dfcf8aac23f4b9daf496a877ea9/packages/std/src/mock.rs#L223

petegordon
  • 339
  • 1
  • 9