frontends/03-frontend. Use Node.js 22.22.2 or newer, copy .env.example to .env.local, and set NEXT_PUBLIC_AUCTION_CONTRACT to your initialized FT/NFT auction. Set NEXT_PUBLIC_NETWORK_ID to the correct network and optionally override NEXT_PUBLIC_RPC_URL.
Getting the data from the contract
Now we have a function to output the whole contract state we will call this function in our frontendindex.js
ft_metadata and nft_token methods on the FT and NFT contracts respectively to get information about the FT and NFT.
Displaying the NFT
We want to show what NFT is being auctioned. To do this we will callnft_token on the NFT contract to get the NFT metadata. To call this method we need to specify the NFT contractId and the token_id, which can be found in the auction information. nft_token also returns the owner of the NFT, so we’ll check this against the contract account to verify that the auction is valid.
index.js
auctionInfo updates because we first need the NFT contract ID and token ID from auctionInfo to make a valid call to nft_token.
In a new component named AuctionItem we display the NFT image, name, and description.
AuctionItem.jsx
ipfs:// URLs through an IPFS gateway, and treats other media values as Arweave IDs.
Fetching FT information
Using the FT contract ID from the auction information, we can call theft_metadata method on the FT contract to get information about the fungible token that is being used for the auction.
index.js
formatUnits to display the highest bid and parseUnits to convert an entered bid into the token’s smallest units. Both helpers use integer arithmetic and return strings so token amounts retain their full precision. The number of decimals comes from ft_metadata; for DAI it is 18.
Bidding with FTs
Instead of calling the functionbid on the contract we now call the ft_transfer_call function on the FT contract. This function transfers the FTs to the auction contract and calls the ft_on_transfer on the auction contract. We attach exactly 1 yoctoNEAR and 300 Tgas to the call.
The result of ft_transfer_call reports how many tokens were used. If it returns zero, the frontend displays an error explaining that the bid was rejected and the tokens refunded. After a successful bid or claim, the page reloads to show the updated state.
index.js
Updating the indexing API call
To display historical bids, add the server-onlyAPI_KEY to .env.local as described in the indexing section. Without this key, the rest of the auction frontend still works.
We need to update the API call that fetches historical bids to now index each time ft_on_transfer is called on the auction contract from the FT contract.
getBidHistory.js
amount. We keep the amount as a string to preserve its precision. The case is the same for the account Id of the bidder, from sender_id.
getBidHistory.js