1st way I tried to do it was to get validator address using this function:
{-# INLINABLE scriptAddress #-}
-- | The address that should be used by a transaction output locked by the given validator script.
scriptAddress :: Validator -> Address
scriptAddress validator = Address (ScriptCredential (validatorHash validator)) Nothing
For example:
-- | The validator script of the game.
gameValidator :: ValidatorScript
gameValidator =
ValidatorScript ($$(Ledger.compileScript [|| validateGuess ||]))
gameAddress :: Address
gameAddress = Ledger.scriptAddress gameValidator
Then use this gameAddress variable as parameter in minting policy, which compiles and works fine.
But real contract address never matches the address parameter, script fails on cardano-cli submit:
txOutputs :: [TxOut]
txOutputs = txInfoOutputs info
ownOutput :: TxOut
ownOutput = case [o | o <- txOutputs, gameAddress == txOutAddress o] of
[o] -> o
_ -> error ()
We always get an error here (I am sure that there is an output to the same smart contract).
This gameAddress has no awareness of mainnet/testnet, maybe that's the reason why it does not match? Maybe there is a way to fix this?
Also, is there a way to simply hardcode smart contract address into Plutus code? Like we can do with PubKeyHash?:
hardcodedPubKeyHash :: PubKeyHash
hardcodedPubKeyHash = "f1befc070bbc16ea613cfc0f0a5c0f856063f1ecbe640556136568f8"