Winning an NFT
No one will enter an auction if there's nothing to win, so let's add a prize. Why not an NFT? NFTs are uniquely identifiable, easily swappable and their logic comes from an external contract so the prize will exist without the auction contract. Let's get to work!
Listing the NFT
When we create an auction we need to list the NFT. To specify which NFT is being auctioned off we need the account ID of the NFT contract and the token ID of the NFT. We will specify these when the contract is initialized; amend init
to add nft_contract
and token_id
as such:
- 🌐 JavaScript
- 🦀 Rust
Loading...
Loading...
Note that token_id
is of type TokenId
which is a String type alias that the NFT standards use for future-proofing.
Transferring the NFT to the winner
When the method claim
is called the NFT needs to be transferred to the highest bidder. Operations regarding NFTs live on the NFT contract, so we make a cross-contract call to the NFT contract telling it to swap the owner of the NFT to the highest bidder. The method on the NFT contract to do this is nft_transfer
.