<p>Here comes the answer: The example code above is a simplified extract of the real code I was running. In the latter, I wasn't setting the value to be minted to the constant 10 but using a function to derive it from a data structure. And here was the problem. It evaluated to 0 because of a small mistake. So I was not minting any receipt-tokens. I had not seen it because another, very similar use case was running without problems.</p>
<p>So the good message is, there is absolutely no issue in Plutus. Minting and distributing tokens to arbitrary output-utxos in a single transaction is absolutely feasible.</p>
<p>Thanks, Mitchell, for the rapid support.</p>

CC BY-SA 4.0
2021-10-15T06:22:22.713Z
2021-10-15T06:22:22.713Z
Jey
<p>I am trying to build a transaction that mints a number of tokens and distributes them to different wallets. Like here:</p>
<pre><code>vote :: forall w s. Poll -&gt; Contract w s Text ()
vote poll = do
  ...
  let lookups = mintingPolicy (receiptPolicyI $ ReceiptPolicy &quot;&quot;)
                &lt;&gt; mintingPolicy (votePolicyI $ VotePolicy &quot;&quot;)
  let tx = (mustMintValue $ assetClassValue voteAC -10)
            &lt;&gt; (mustMintValue $ assetClassValue receiptAC 10)
            &lt;&gt; (mustPayToPubKey wallet1 (assetClassValue receiptAC 5))
            &lt;&gt; (mustPayToPubKey wallet2 (assetClassValue receiptAC 5))
  ledgerTx &lt;- submitTxConstraintsWith @Polling lookups tx
</code></pre>
<p>In this example 10 votes are burned and 10 receipts are minted. The 10 receipts shall be paid to 2 wallets.</p>
<p>Now when I test this, an error is thrown. It complains that there are insufficient funds in the wallet that submits the transaction. It says that 10 assets of type receiptAC are missing.</p>
<p>Now, of course these assets are missing in the wallet because I want to mint them in the same transaction that also distributes them.</p>
<p>How can I achieve this ? Maybe I am using <code>mustPayToPubKey</code> wrong and should indicate the distribution differently.</p>

CC BY-SA 4.0
2021-10-13T23:04:50.043Z
Are you testing with the emulator trace? Is the error from the emulator? 
I'd recommend constraining everything so the only thing you're trying to do is mint to two wallets: remove the vote stuff and set your minting policies to just `True`.
Mitchell Turner
CC BY-SA 4.0
2021-10-13T23:05:43.953Z
In fact, can you include your entire error message in your question?
Mitchell Turner
CC BY-SA 4.0
2021-10-14T07:34:40.537Z
Hi Mitchell, thank you for the feedback. I'm testing in the emulator trace and printing out additional logs to trace. I'll simplify the code and test again. Your comment gives me confidence that it is an error on my part. I was already afraid that this behaviour was expected. That would have been very bad for me : ).
Jey
CC BY-SA 4.0
2021-10-14T22:26:29.323Z
I'd suggest you introduce delay between the transaction doing the minting and the transaction that pays into the different `PubKeyHash` by not submitting them in one transaction.
Aoaddeola
<plutus><transaction><minting>
Minting and distributing to different wallets
# Minting and distributing to different wallets

(Asked by: username_0 on 2021-10-13)

I am trying to build a transaction that mints a number of tokens and distributes them to different wallets. Like here:
vote :: forall w s. Poll -> Contract w s Text ()
vote poll = do
  ...
  let lookups = mintingPolicy (receiptPolicyI $ ReceiptPolicy "")
                <> mintingPolicy (votePolicyI $ VotePolicy "")
  let tx = (mustMintValue $ assetClassValue voteAC -10)
            <> (mustMintValue $ assetClassValue receiptAC 10)
            <> (mustPayToPubKey wallet1 (assetClassValue receiptAC 5))
            <> (mustPayToPubKey wallet2 (assetClassValue receiptAC 5))
  ledgerTx <- submitTxConstraintsWith @Polling lookups tx

In this example 10 votes are burned and 10 receipts are minted. The 10 receipts shall be paid to 2 wallets.
Now when I test this, an error is thrown. It complains that there are insufficient funds in the wallet that submits the transaction. It says that 10 assets of type receiptAC are missing.
Now, of course these assets are missing in the wallet because I want to mint them in the same transaction that also distributes them.
How can I achieve this ? Maybe I am using mustPayToPubKey wrong and should indicate the distribution differently.

**Tags:** plutus, transaction, minting
> **Comments:**
> **username_1**: Are you testing with the emulator trace? Is the error from the emulator?  I'd recommend constraining everything so the only thing you're trying to do is mint to two wallets: remove the vote stuff and set your minting policies to just `True`.  
> **username_1**: In fact, can you include your entire error message in your question?  
> **username_0**: Hi Mitchell, thank you for the feedback. I'm testing in the emulator trace and printing out additional logs to trace. I'll simplify the code and test again. Your comment gives me confidence that it is an error on my part. I was already afraid that this behaviour was expected. That would have been very bad for me : ).  
> **username_2**: I'd suggest you introduce delay between the transaction doing the minting and the transaction that pays into the different `PubKeyHash` by not submitting them in one transaction.  

---

## 1 answers

### Answer by username_0 on 2021-10-15. Score: 3 | Accepted answer

Here comes the answer: The example code above is a simplified extract of the real code I was running. In the latter, I wasn't setting the value to be minted to the constant 10 but using a function to derive it from a data structure. And here was the problem. It evaluated to 0 because of a small mistake. So I was not minting any receipt-tokens. I had not seen it because another, very similar use case was running without problems.

So the good message is, there is absolutely no issue in Plutus. Minting and distributing tokens to arbitrary output-utxos in a single transaction is absolutely feasible.

Thanks, Mitchell, for the rapid support.


---

