<p><strong>Q1</strong>: As @Travis mentioned, that's the way the offchain code was implemented. Try as follows and you'll have a second opportunity to bid.</p>
<pre><code>bid :: forall w s. BidParams -&gt; Contract w s Text ()
bid BidParams{..} = do
  (oref, o, d@AuctionDatum{..}) &lt;- findAuction bpCurrency bpToken
  logInfo @P.String $ printf &quot;found auction utxo with datum %s&quot; (P.show d)

  if (bpBid &lt; minBid d) 
    then logError @P.String $ printf &quot;bid lower than minimal bid %d&quot; (minBid d)
    else do 
        pkh &lt;- ownPaymentPubKeyHash
        let b  = Bid {bBidder = pkh, bBid = bpBid}
            d' = d {adHighestBid = Just b}
            v  = Value.singleton bpCurrency bpToken 1 &lt;&gt; Ada.lovelaceValueOf (minLovelace + bpBid)
            r  = Redeemer $ PlutusTx.toBuiltinData $ MkBid b

            lookups = Constraints.typedValidatorLookups typedAuctionValidator P.&lt;&gt;
                    Constraints.otherScript auctionValidator                P.&lt;&gt;
                    Constraints.unspentOutputs (Map.singleton oref o)
            tx      = case adHighestBid of
                        Nothing      -&gt; Constraints.mustPayToTheScript d' v                            &lt;&gt;
                                        Constraints.mustValidateIn (to $ aDeadline adAuction)          &lt;&gt;
                                        Constraints.mustSpendScriptOutput oref r
                        Just Bid{..} -&gt; Constraints.mustPayToTheScript d' v                            &lt;&gt;
                                        Constraints.mustPayToPubKey bBidder (Ada.lovelaceValueOf bBid) &lt;&gt;
                                        Constraints.mustValidateIn (to $ aDeadline adAuction)          &lt;&gt;
                                        Constraints.mustSpendScriptOutput oref r
        ledgerTx &lt;- submitTxConstraintsWith lookups tx
        void $ awaitTxConfirmed $ getCardanoTxId ledgerTx
        logInfo @P.String $ printf &quot;made bid of %d lovelace in auction %s for token (%s, %s)&quot;
            bpBid
            (P.show adAuction)
            (P.show bpCurrency)
            (P.show bpToken)
</code></pre>

CC BY-SA 4.0
2022-01-16T17:24:03.910Z
2022-01-16T17:24:03.910Z
kindofdev
<p><strong>For question 1</strong>: It seems to be an issue with the way the English Auction contract is written. I believe this is a bug that someone with more knowledge of Plutus would be able to fix in the contract code.</p>
<p><strong>For question 2</strong>:</p>
<p>When Wallet 2 was outbid, the script created a UTxO to give it back Wallet 2's original 11000000 bid.</p>
<p>When Wallet 2 bid again, it bid 15000000. First the unspent 11000000 was used as an input, but that's not enough to cover the 15000000 bid. So Wallet 2's other UTxO containing 88991363 is needed as an additional input.</p>

CC BY-SA 4.0
2022-01-16T22:25:47.987Z
Note: I have suggested the original poster break this into two questions.
gRebel
CC BY-SA 4.0
2022-01-16T16:47:16.467Z
2022-01-16T16:47:16.467Z
Travis
<p>I've been toying around with the English Auction example and I have two questions:</p>
<ol>
<li><p>After an invalid bid (less than the minimum bet set for the auction) from a wallet, a second valid bid from the same wallet is also not successful. Is this intended? The trace shows the first invalid bid but not the second one, the last trace message is &quot;Contract instance stopped with error: &quot;bid lower than minimal bid 10000000&quot;.</p>
</li>
<li><p>Considering the following sequence of actions: auction starts, wallet 2 bids, wallet 3 outbids wallet 2, wallet 2 outbids wallet 3, auction closes. The image below shows the transaction corresponding to the second bid of wallet 2. Why do we have wallet 2 twice as an input of the transaction? I thought only wallet 2 created by slot 3 should appear as an input.
<a href="https://i.sstatic.net/CbO73.png" rel="noreferrer"><img src="https://i.sstatic.net/CbO73.png" alt="enter image description here" /></a></p>
</li>
</ol>

CC BY-SA 4.0
2022-01-16T13:03:39.560Z
For (1), anytime someone bids < minumum, the contract does "throwError" which seems to cause this problem. I would have thought that just the wallet/transcation that bids would fail, not the entire smart contract !
wakathi
CC BY-SA 4.0
2022-01-16T22:22:26.823Z
You're right, this should be two questions (you will get twice the votes and reputation).  It will probably help you to write a better title for the questions too.  e.g. "English auction: Is prevention of valid bid by previous invalid bid intended behavior?"
gRebel
<plutus-pioneer-program>
testing the English Auction example
# testing the English Auction example

(Asked by: username_0 on 2022-01-16)

I've been toying around with the English Auction example and I have two questions:

1. After an invalid bid (less than the minimum bet set for the auction) from a wallet, a second valid bid from the same wallet is also not successful. Is this intended? The trace shows the first invalid bid but not the second one, the last trace message is "Contract instance stopped with error: "bid lower than minimal bid 10000000".
2. Considering the following sequence of actions: auction starts, wallet 2 bids, wallet 3 outbids wallet 2, wallet 2 outbids wallet 3, auction closes. The image below shows the transaction corresponding to the second bid of wallet 2. Why do we have wallet 2 twice as an input of the transaction? I thought only wallet 2 created by slot 3 should appear as an input.
   [![enter image description here](https://i.sstatic.net/CbO73.png)](https://i.sstatic.net/CbO73.png)

**Tags:** plutus-pioneer-program
> **Comments:**
> **username_1**: For (1), anytime someone bids < minumum, the contract does "throwError" which seems to cause this problem. I would have thought that just the wallet/transcation that bids would fail, not the entire smart contract !  
> **username_2**: You're right, this should be two questions (you will get twice the votes and reputation).  It will probably help you to write a better title for the questions too.  e.g. "English auction: Is prevention of valid bid by previous invalid bid intended behavior?"  

---

## 2 answers

### Answer by username_3 on 2022-01-16. Score: 1

Q1: As @Travis mentioned, that's the way the offchain code was implemented. Try as follows and you'll have a second opportunity to bid.
bid :: forall w s. BidParams -> Contract w s Text ()
bid BidParams{..} = do
  (oref, o, d@AuctionDatum{..}) <- findAuction bpCurrency bpToken
  logInfo @P.String $ printf "found auction utxo with datum %s" (P.show d)

  if (bpBid < minBid d) 
    then logError @P.String $ printf "bid lower than minimal bid %d" (minBid d)
    else do 
        pkh <- ownPaymentPubKeyHash
        let b  = Bid {bBidder = pkh, bBid = bpBid}
            d' = d {adHighestBid = Just b}
            v  = Value.singleton bpCurrency bpToken 1 <> Ada.lovelaceValueOf (minLovelace + bpBid)
            r  = Redeemer $ PlutusTx.toBuiltinData $ MkBid b

            lookups = Constraints.typedValidatorLookups typedAuctionValidator P.<>
                    Constraints.otherScript auctionValidator                P.<>
                    Constraints.unspentOutputs (Map.singleton oref o)
            tx      = case adHighestBid of
                        Nothing      -> Constraints.mustPayToTheScript d' v                            <>
                                        Constraints.mustValidateIn (to $ aDeadline adAuction)          <>
                                        Constraints.mustSpendScriptOutput oref r
                        Just Bid{..} -> Constraints.mustPayToTheScript d' v                            <>
                                        Constraints.mustPayToPubKey bBidder (Ada.lovelaceValueOf bBid) <>
                                        Constraints.mustValidateIn (to $ aDeadline adAuction)          <>
                                        Constraints.mustSpendScriptOutput oref r
        ledgerTx <- submitTxConstraintsWith lookups tx
        void $ awaitTxConfirmed $ getCardanoTxId ledgerTx
        logInfo @P.String $ printf "made bid of %d lovelace in auction %s for token (%s, %s)"
            bpBid
            (P.show adAuction)
            (P.show bpCurrency)
            (P.show bpToken)


---

### Answer by username_4 on 2022-01-16. Score: 1

**For question 1**: It seems to be an issue with the way the English Auction contract is written. I believe this is a bug that someone with more knowledge of Plutus would be able to fix in the contract code.

**For question 2**:

When Wallet 2 was outbid, the script created a UTxO to give it back Wallet 2's original 11000000 bid.

When Wallet 2 bid again, it bid 15000000. First the unspent 11000000 was used as an input, but that's not enough to cover the 15000000 bid. So Wallet 2's other UTxO containing 88991363 is needed as an additional input.

> **Comments:**
> **username_2**: Note: I have suggested the original poster break this into two questions.  

---

