Auctioning App

Deploying an auctioning App using the Andromeda CLI.

If unfamiliar with the steps of deploying an app, go back to the first example where we explain in detail all the different parts of deploying an App.

Defining our App

You can also use a CW20 token as the bidding token. You ca read more about the Auction ADO if you are interested in testing out variations on this App.

For this example, we will be building a simple auction app that holds auction sales on NFTs using a native token for bidding. We only need two components/ADOs:

We will perform the following steps:

  • Mint an NFT

  • Send it to auction starting an auction on it

  • Place bids on the NFT

  • End the auction

  • Claim the funds and transfer the NFT to the new owner

The Steps of Deploying an App

We already have an ADODB contract with saved code IDs of the ADOs and Kernel ADO deployed. These addresses can be found in Deployed Contracts section. This means that to deploy an App we only need to instantiate it through the CLI.

Defining the Instantiation Messages

For this app we would need only 2 components:

Let us first start by representing the instantiation message for each of our ADOs:

CW721

{
"name":"AuctionNFTs",
"symbol":"ANFT",
"minter":"<your-address>",
"kernel_address":"andr14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9shptkql"
}

As base64:

eyJuYW1lIjoiQXVjdGlvbk5GVHMiLCJzeW1ib2wiOiJBTkZUIiwibWludGVyIjoiYW5kcjFnemsybTBrNDBlMzB3bjZ3djlqOWtjcng0bGpsazRrczh3aHJncSIsImtlcm5lbF9hZGRyZXNzIjoiYW5kcjE0aGoydGF2cThmcGVzZHd4eGN1NDRydHkzaGg5MHZodWpydmNtc3RsNHpyM3R4bWZ2dzlzaHB0a3FsIn0=

Auction

Here we specify which CW721 is permitted to send NFTs to the auction. We reference the CW721 of our app through the name.

{
"authorized_token_addresses":["./tokens"],
"kernel_address":"andr14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9shptkql"
}

As base64:

eyJhdXRob3JpemVkX3Rva2VuX2FkZHJlc3NlcyI6WyIuL3Rva2VucyJdLCJrZXJuZWxfYWRkcmVzcyI6ImFuZHIxNGhqMnRhdnE4ZnBlc2R3eHhjdTQ0cnR5M2hoOTB2aHVqcnZjbXN0bDR6cjN0eG1mdnc5c2hwdGtxbCJ9

App

{
  "name": "AuctionApp",
  "app_components": [
    {
      "name": "auction",
      "ado_type": "auction",
      "component_type":{
       "new":"eyJhdXRob3JpemVkX3Rva2VuX2FkZHJlc3NlcyI6WyIuL3Rva2VucyJdLCJrZXJuZWxfYWRkcmVzcyI6ImFuZHIxNGhqMnRhdnE4ZnBlc2R3eHhjdTQ0cnR5M2hoOTB2aHVqcnZjbXN0bDR6cjN0eG1mdnc5c2hwdGtxbCJ9"
       }
     },
    {
      "name": "tokens",
      "ado_type": "cw721",
      "component_type":{
      "new":"eyJuYW1lIjoiQXVjdGlvbk5GVHMiLCJzeW1ib2wiOiJBTkZUIiwibWludGVyIjoiYW5kcjFnemsybTBrNDBlMzB3bjZ3djlqOWtjcng0bGpsazRrczh3aHJncSIsImtlcm5lbF9hZGRyZXNzIjoiYW5kcjE0aGoydGF2cThmcGVzZHd4eGN1NDRydHkzaGg5MHZodWpydmNtc3RsNHpyM3R4bWZ2dzlzaHB0a3FsIn0="
       }
    }
  ],
  "kernel_address":"andr14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9shptkql"
  }

There are several components found here. A simple name for the app, the components of the app itself and a reference to the “Kernel”. Each component of the app provides two values: a name used for referencing for other components within the app, and the base64 encoded instantiation message.

Instantiating the App

If you do not have the CLI downloaded, go to the Introduction to Apps section to get the latest version.

First, let us open the CLI by running andr in our terminal. We then need to choose the chain we want to deploy on. Run "chain use" in the CLI and select the testnet that you want to deploy on. For this example I will be using the Andromeda test-net Galileo-3.

We have already uploaded the App ADO to the Andromeda testnet. A simple way to check the latest code id for the App ADO is to query it from the ADODB using the chain you want to use.

In the CLI, while connected to the chain of choice, run:

os adodb getcodeid app-contract

The code Id to use will be returned.

Now we can instantiate our App. We will be using our wasm command to instantiate our app:

 wasm instantiate <app-code-id> '{"name": "AuctionApp","app_components": [{"name": "auction","ado_type": "auction","component_type":{"new":"eyJhdXRob3JpemVkX3Rva2VuX2FkZHJlc3NlcyI6WyIuL3Rva2VucyJdLCJrZXJuZWxfYWRkcmVzcyI6ImFuZHIxNGhqMnRhdnE4ZnBlc2R3eHhjdTQ0cnR5M2hoOTB2aHVqcnZjbXN0bDR6cjN0eG1mdnc5c2hwdGtxbCJ9"}},{"name": "tokens","ado_type": "cw721","component_type":{"new":"eyJuYW1lIjoiQXVjdGlvbk5GVHMiLCJzeW1ib2wiOiJBTkZUIiwibWludGVyIjoiYW5kcjFnemsybTBrNDBlMzB3bjZ3djlqOWtjcng0bGpsazRrczh3aHJncSIsImtlcm5lbF9hZGRyZXNzIjoiYW5kcjE0aGoydGF2cThmcGVzZHd4eGN1NDRydHkzaGg5MHZodWpydmNtc3RsNHpyM3R4bWZ2dzlzaHB0a3FsIn0="}}],"kernel_address":"andr14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9shptkql"}'

Transaction

Interacting with the App

Mint Tokens

We will only mint one NFT to auction:

{
"mint": {
            "token_id":"1",
            "owner":"<your-address>",
            "token_uri":"https://gateway.pinata.cloud/ipfs...",
            "extension": {
                "publisher": "Andromeda"
              }            
        }
}
wasm execute <cw721-contract-address> '{"mint": {"token_id":"1","owner":"andr1gzk2m0k40e30wn6wv9j9kcrx4ljlk4ks8whrgq","token_uri":"https://gateway.pinata.cloud/ipfs...","extension": {"publisher": "Andromeda"}}}'

Mint Token

Start Auction

In order to start an auction on our token, we need to send it to the auction contract with the required message.

{
    "send_nft": {
        "contract": "<auction-contract-address>",
        "token_id": "1",
        "msg": "eyJzdGFydF9hdWN0aW9uIjogeyJlbmRfdGltZSI6IDE3MTYyMjgwNDczMDgsInVzZXNfY3cyMCI6IGZhbHNlLCJjb2luX2Rlbm9tIjogInVhbmRyIiwibWluX2JpZCI6IjUwMCIsInJlY2lwaWVudCI6eyJhZGRyZXNzIjoiYW5kcjFnemsybTBrNDBlMzB3bjZ3djlqOWtjcng0bGpsazRrczh3aHJncSJ9fX0="
    }
}

The attached message is a start_auction message to start the auction when the NFT is sent.

{
"start_auction": {
        "end_time": 1716228047308,
        "uses_cw20": false,
        "coin_denom": "uandr",
        "min_bid":"500"
        "recipient":{
                "address":"<Your-wallet-address>"
                }
        }
   }
wasm execute <cw721-contract-address> '{"send_nft": {"contract": "andr1tg80hn4luwa8mn9xs0lspaujfume55m269cykut6nlahc8asww7s0xga6h","token_id": "1","msg": "eyJzdGFydF9hdWN0aW9uIjogeyJzdGFydF90aW1lIjogMTcwMDgzODU1MDE0MSwiZHVyYXRpb24iOiA2MDAwMDAsImNvaW5fZGVub20iOiAidWFuZHIiLCJtaW5fYmlkIjoiNTAwIn19"}}' 

Start Auction

Place Bids

Now it is time to start placing some bids on our NFT.

{
    "place_bid": {
        "token_id": "1",
        "token_address":"<cw721-contract-address>"
    }
}
wasm execute <auction-contract-address> '{ "place_bid": { "token_id": "1","token_address":"<cw721-contract-address>"}}'

Bid 600uandr

Bid 2000uandr

Let us query the Bids of the auction to see if they match:

{
 "bids":{
    "auction_id": "1"
    }
 }
wasm query <auction-contract-address> '{"bids":{"auction_id": "1"}}' 

Result

{
  "bids": [
    {
      "bidder": "andr1v0an0ar6js3kwmgwr6pp5kuswm6wh0gwdnjska",
      "amount": "600",
      "timestamp": "1716227571751876738"
    },
    {
      "bidder": "andr1dzrcm9swj22v2d05sqfktlwrz3u8hskgujyqhk",
      "amount": "2000",
      "timestamp": "1716227601915954109"
    }
  ]
}

After the Auction has concluded, it is time to claim the NFT for the buyer and funds for the seller.

Claim the NFT

{
    "claim": {
        "token_id": "1",
        "token_address":"<cw721-contract-address>"
    }
}
wasm execute <auction-contract-address> '{"claim": {"token_id": "1","token_address":"<cw721-contract-address>"}}'  

Transaction

The funds will be sent to the seller and the NFT to the winning bid. We can check the NFT owner after claiming by querying our NFT contract:

wasm query <cw721-contract-address> '{"owner_of": {"token_id": "1","include_expired": false}}'

The returned owner should be the highest bidder.

Conclusion

Congratulations, we have built a fully functioning auctioning App that allows you to auction off your NFTs. Keep in mind that all the apps we build in these examples are highly customizable to satisfy user needs. We can change the accepted funds, add/remove whitelists, and even add more components to our App if needed.

Was this helpful?