user2787: Suppose we want a smart contract (validator script) that locks a user' fund (e.g. ADA) that she deposits and releases it back if she withdraws it. Suppose when she deposits some fund into the validator script, we want in the same transaction the validator script sends her wallet some native tokens as a proof of deposit.
In this scenario, how can the validator script mints some native tokens in the same transaction as a user sends some fund to the validator script?

user1130: You need a separate minting policy to mint the tokens.

we want a smart contract (validator script)

I tend to think of smart contracts as including a set of validators and policies, not just one script. It's typical to use multiple in concert.
Essentially the validator holds an NFT with a datum tracking the contract's state. The validator constrains any transaction spending the datum, and checks that the transaction

deposits/withdraws the correct amount,
mints/burns the correct amount, and
replaces the NFT + datum with updated state

The the minting policy will only mint if the NFT is spent--all the logic is on the validator side.
Check out the discussion on "dummy nfts"/"access tokens" here to get a better idea of how that would work.

2787: <p>Suppose we want a smart contract (validator script) that locks a user' fund (e.g. ADA) that she deposits and releases it back if she withdraws it. Suppose when she deposits some fund into the validator script, we want in the same transaction the validator script sends her wallet some native tokens as a proof of deposit.</p>
<p>In this scenario, how can the validator script mints some native tokens in the same transaction as a user sends some fund to the validator script?</p>
 1130: <p>You need a separate minting policy to mint the tokens.</p>
<blockquote>
<p>we want a smart contract (validator script)</p>
</blockquote>
<p><em>I tend to think of smart contracts as including a set of validators and policies, not just one script. It's typical to use multiple in concert.</em></p>
<p>Essentially the validator holds an NFT with a datum tracking the contract's state. The validator constrains any transaction spending the datum, and checks that the transaction</p>
<ol>
<li>deposits/withdraws the correct amount,</li>
<li>mints/burns the correct amount, and</li>
<li>replaces the NFT + datum with updated state</li>
</ol>
<p>The the minting policy will only mint if the NFT is spent--all the logic is on the validator side.</p>
<p>Check out the discussion on &quot;dummy nfts&quot;/&quot;access tokens&quot; <a href="https://cardano.stackexchange.com/a/4818/1130">here</a> to get a better idea of how that would work.</p>
