Bid in an optimistic auction

This guide walks through submitting a bid to the optimistic auctions precompile and waiting for the bid set to finalize. For background on how optimistic auctions work, see Optimistic Auctionsarrow-up-right.

Submit a bid

A bid is a transaction to the submitBid function on the precompile. Each bid specifies an auction_id (which auction to join), a deadline (in microseconds), a value (application-defined score or price), and a data payload (e.g. an encoded intent or signed transaction).

import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://rpc.v1.dev.pod.network");
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);

const AUCTION = "0xeDD0670497E00ded712a398563Ea938A29dD28c7";
const abi = [
  "function submitBid(uint256 auction_id, uint64 deadline, uint256 value, bytes data)",
  "event BidSubmitted(uint256 indexed auction_id, address indexed bidder, uint64 indexed deadline, uint256 value, bytes data)",
];
const auction = new ethers.Contract(AUCTION, abi, wallet);

const auctionId = 1n;
const deadline = BigInt(Date.now()) * 1000n + 10_000_000n; // 10 seconds from now, in microseconds
const value = ethers.parseEther("100");                     // application-defined bid value
const data = "0x";                                          // opaque payload

const tx = await auction.submitBid(auctionId, deadline, value, data);
console.log("Bid tx:", tx.hash);
circle-exclamation

Wait for the bid set to finalize

After submitting a bid, call pod_waitPastPerfectTime to block until the past perfect certificate is available for the auction deadline. Once it returns, the bid set is complete.

Fetch the finalized bid set

Once past perfection is reached, query the BidSubmitted event logs to read all bids in the auction.

Last updated