get_contract_code_hash
get_contract_code_hash helper function
Last updated
Was this helpful?
get_contract_code_hash helper function
Last updated
Was this helpful?
To retrieve a Secret Network smart contract's code hash from within a Secret contract call, you can use to directly query the on-chain data from inside the contract.
This helper function is particularly interesting if you desire to make complicated contract structures that involve submessages or just cross-contract messages to different Secret Network contracts. With this code snippet, you do not need to supply the code_hash
of each contract that you are going to call in submessage or normal messages. It is sufficient to know the contract address of the other contract, the code snipped will fetch the latest on chain code_hash
for you.
Be aware that contracts can be upgraded on Secret Network! Since this code snippet always fetch the code_hash
directly from the chain without any extra check (which was implictly done by manually supplying the code_hash
), you need to be careful about silently (perhaps maliciously) upgraded contracts which potentially releveal confidential information.
The Secret Network has designed a helper function, get_contract_code_hash
, exactly for this purpose.
Simply add the Anybuf package and the "stargate"
feature for cosmwasm-std to your cargo.toml
:
And then add the function to your contract: