user4137: 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"


user387: If it does not match, it means your off-chain code is using a different address than what you expect on-chain.
An address is comprised of two parts, the payment and the staking part. You seem to be calculating the address of the payment part being the ValidatorHash of your game script and the staking part to be Nothing.
Maybe your off-chain code is creating the address slightly differently?
There is a function scriptOutputsAt in V1/V2 plutus (https://github.com/input-output-hk/plutus/blob/5cc518f1202930ad52b8ba838af32af084c0e754/plutus-ledger-api/src/Plutus/V1/Ledger/Contexts.hs#L251-L258) which you could also use. It explicitly only looks at the payment part and ignores the staking part.

4137: <p>1st way I tried to do it was to get validator address using this function:</p>
<pre><code>{-# INLINABLE scriptAddress #-}
-- | The address that should be used by a transaction output locked by the given validator script.
scriptAddress :: Validator -&gt; Address
scriptAddress validator = Address (ScriptCredential (validatorHash validator)) Nothing
</code></pre>
<p>For example:</p>
<pre><code>-- | The validator script of the game.
gameValidator :: ValidatorScript
gameValidator =
    ValidatorScript ($$(Ledger.compileScript [|| validateGuess ||]))

gameAddress :: Address
gameAddress = Ledger.scriptAddress gameValidator
</code></pre>
<p>Then use this gameAddress variable as parameter in minting policy, which compiles and works fine.</p>
<p>But real contract address never matches the address parameter, script fails on cardano-cli submit:</p>
<pre><code>txOutputs :: [TxOut]
txOutputs = txInfoOutputs info

ownOutput :: TxOut
ownOutput = case [o | o &lt;- txOutputs, gameAddress == txOutAddress o] of
[o] -&gt; o
_ -&gt; error ()
</code></pre>
<p>We always get an error here (I am sure that there is an output to the same smart contract).</p>
<p>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?</p>
<p>Also, is there a way to simply hardcode smart contract address into Plutus code? Like we can do with PubKeyHash?:</p>
<pre><code>hardcodedPubKeyHash :: PubKeyHash
hardcodedPubKeyHash = &quot;f1befc070bbc16ea613cfc0f0a5c0f856063f1ecbe640556136568f8&quot;
</code></pre>
 387: <p>If it does not match, it means your off-chain code is using a different address than what you expect on-chain.</p>
<p>An address is comprised of two parts, the payment and the staking part. You seem to be calculating the address of the payment part being the <code>ValidatorHash</code> of your game script and the staking part to be <code>Nothing</code>.</p>
<p>Maybe your off-chain code is creating the address slightly differently?</p>
<p>There is a function <code>scriptOutputsAt</code> in V1/V2 <code>plutus</code> (<a href="https://github.com/input-output-hk/plutus/blob/5cc518f1202930ad52b8ba838af32af084c0e754/plutus-ledger-api/src/Plutus/V1/Ledger/Contexts.hs#L251-L258" rel="nofollow noreferrer">https://github.com/input-output-hk/plutus/blob/5cc518f1202930ad52b8ba838af32af084c0e754/plutus-ledger-api/src/Plutus/V1/Ledger/Contexts.hs#L251-L258</a>) which you could also use. It explicitly only looks at the payment part and ignores the staking part.</p>
