# Submit Bid

Once an `auctionStarted` event has been seen, searchers can start submitting bids.

The Bid with the highest `bid_amount` wins, while paying exactly that amount.

## Conditions for a Bid to be accepted

A Bid must satisfy all conditions below in order to be accepted. Please read very carefully as this is **extremely** crucial.

* A Bid can be submitted before the given deadline (specified by `deadlineTimestampMs`). Since that window may be extremely short (usually 200-300ms), it is strongly recommended to host your services in **Frankfurt, Germany**, to avoid unnecessary round trips.
* A Bid **MUST** have a lexicologically larger transaction digest comparing to opportunity transaction's.  Comparison is done with the two digests' binary form (represented as 32-byte binaries), rather than base-58 encoded.  This is because in the implementation of [Soft Bundle (SIP-19)](https://github.com/sui-foundation/sips/blob/main/sips/sip-19.md) , we choose the transaction with the smallest digest to determine submission order.  One way to achieve this is to keep increasing gas budget by 1, until the digest of the transaction satisfies.
* A bid must has the exact `gas_price` as the opportunity transaction's.
* A bid must not lock any object that has already been locked by the opportunity transaction.
* A bid must contain a MoveCall to the `submit_bid` method of the Shio package, paying exactly `bid_amount`, see [Interact with Shio Contract](https://docs.getshio.com/searcher-guides/interact-with-shio-contract).
* A bid must pass dry-run in the bundle of \[opportunity transaction, bid].

## Bid Submission

There are two ways for submitting bid:

* A Bid can be submitted by directly sending through the Feed WebSocket connection. This approach appears to be simpler (by not having to maintain more than one client), however, in case of bid rejection, exact reason will not be returned.
* Or alternatively, a bid can also be submitted through JSON-RPC method `shio_submitBid`. An error message will be returned directly, explaining why the bid has been rejected if that is the case.

### Submission through WebSocket

Send a message in the following format through the Feed WebSocket connection:

```json
{
  "oppTxDigest": "E72mG9GCroPgaw9uoeGiKLzAfd9CZq82iGDjypKdzYG7",
  "bidAmount": 42000000000,
  "txData": "base64Encoded",
  "sig": "base64Encoded"
}
```

* `bidAmount` is in terms of MIST. This is the amount that needs to be paid on successful execution.
* `txData`: Base64-encoded bcs-serialized TransactionData without signature.
* `sig`: Base64-encoded signature. We currently only support ED25519 signature scheme.

Make sure the bid is sent within the given Auction Window.

Once sent, the bid will either be accepted or rejected, however, no response will be given.

For troubleshooting, please refer to Submission through JSON-RPC .

### Submission through JSON-RPC

Send a JSON-RPC request to `https://rpc.getshio.com` in the following format:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "shio_submitBid",
  "params": [
    "E72mG9GCroPgaw9uoeGiKLzAfd9CZq82iGDjypKdzYG7",
    42000000000,
    "txDataBase64Encoded",
    "sigBase64Encoded"
  ]
}
```

A response will be returned, containing error message if any.

We do not recommend this approach in production, as extra RTTs may be incurred due to HTTP/TLS handshake.
