Clarity Smart Contracts Check if function caller is contract

30 views Asked by At

I have a question .... I have 2 contracts, let's call them contract1 and contract2. Contract1 executes a function that contract2 holds... Is there possible to check if the function caller (tx-sender) is the contract1?

I've tried using is-eq or something like that (asserts! (is-eq CONTRACT_ADDRESS tx-sender) ONLY_CONTRACT_ALLOWED), but how do I assign the value of CONTRACT_ADDRESS as contract1 from contract2?

1

There are 1 answers

0
Kenny On

You can hardcode the deployed contract principal, this may be a solution that doesn't require you hard code the CONTRACT_ADDRESS, you can instead call it as a trait reference: https://book.clarity-lang.org/ch13-03-contract-upgradability.html