Venom In Action. Simple NFT auction

This guide shows you how you can perform on-chain interaction with previously deployed TIP-4 token

This guide will be more complicated as compared with Tokensale implementation. It's recommended to pass it secondarily.

Fist of all, as usual, we should setup our development environment with locklift. For this smart-contracts guideline you need to include both TIP-3 and TIP-4 dependencies, because our Auction will be accepted in TIP-3 tokens. Let's explore some scheme of our contracts interaction and describe it

Our smart-contracts interaction logic

NFT creating is a green arrows flow, auction bids is a yellow. Let's describe a processes

  1. User mints its own NFT via Collection contract

  2. Then user deploys an Auction

  3. Auction deploys its own TIP-3 TokenWallet via given TokenRoot address (familiar mechanic for you from TIP-3 Tokensale guide)

  4. User sends minted NFT to Auction, which one implementing INftTransfer interface and accept this NFT

  5. Another users sends TIP-3 tokens (bid) to Auction with notify = true parameter (see TIP-3 specs or TIP-3 guide)

  6. Auction's TokenWallet send a callback to Auction, which one handle TIP-3 transfer - checks if incoming bid amount more than previous bid, and updates a leader bid address

  7. When time is over, finishAuction function will send NFT to auction winner or old owner, if there is no bids was accepted

That's all! As you can see, the main mechanic of our interaction is a callbacks. Let's start implement our contracts. First, implement Collection and NFT contracts same as in TIP-4 quick start guide.

We won't explain this code blocks because of it's already done in TIP-4 quick start

Then, let's deal with Auction contract. We'll get started from state and constructor, as usual. Do not forget to add interfaces we need.

Remember about gas management and token wallet deploying mechanics from previous Venom In Action guide. Implement onTokenWallet callback the same way.

Ok, the next callback we need is onNftTransfer, that will be called when NFT owner send NFT to Auction address

Great! Now we are ready to accept bids. Let's implement another callback onAcceptTokensTransfer, that our TokenWallet will call any time it got an incoming token transaction. Take attention! This is the main logic of our auction!

That's it. How hard is that? The last thing we need - finishAuction function.

You can explore this sample (with tests and some scripts) by going to this <todo: link> repository. But we should talks about scripts we need, because this sample needs not only deploy scripts. Moving on.

We can take collection deploying script and NFT minting scripts from TIP-4 quick start. Script for auction deploying not a really hard too.

The next script, that can be useful for you - sending NFT to Auction. Let's code

Pay attention on callback parameter of NFT's transfer method

This is really important step. You may lose your NFT if don't specify callback for our auction, because callback onNftTransfer won't be called. Same idea should be used by your auction participants. They should send TIP-3 tokens to Auction with notify: true parameter:

All you need now is a write some tests with locklift supports. This all-in-one example with locklift environment, some simple tests and deploy scripts is available in repo.

Last updated