Auctioning App

Deploying an auctioning App using the Andromeda CLI.

If any of the messages in this example do not work, you might want to cross reference the messages with the ADO specific section which always contains the latest ADO versions to make sure they are correct. Other than that the logic will remain the same.

Make sure to read the Introduction to Apps before going through building 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.

You will need the deployed Kernel contract address as it needs to be specified when instantiating any ADO.

Defining the Instantiation Messages

For this app we would need only 2 components:

Although not necessary, if you are unfamiliar with these ADOs, it is suggested to read through each of the them before deploying an app.

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

Keep in mind that the app takes these messages as base64 encoded.

CW721

Make sure to set the minter as your own address. If you do not change the minter, you will not be able to mint any tokens.

{
"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

The Kernel address used here might be outdated in the future. Check our deployed contracts to get the latest Kernel or run "chain config" in CLI which will also display the address.

The instantiate_msg for the cw721 will not be the same for you as you should specify the minter address as your own. Make sure to replace it with the base64 message that you got.

{
  "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.

If this is the first time using the CLI make sure to run "wallet add <wallet-name>"in order to create a wallet. Then go to that chain's faucet (usually located in their discord) and request tokens.

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:

Note that the instantiation message will not be the exact same for you since you will be using a different recipient address.

Do not copy and paste the command below as it will not work. Make sure to make the appropriate changes before running the command.

Replace the <code_id> with the returned code-id for the app ADO.

 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

You will be using the contract addresses that were instantiated for you instead of the ones in this tutorial.

Interacting with the App

Mint Tokens

We will only mint one NFT to auction:

Make sure to replace <your-address> with the address you are using for the owner field.

{
"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.

You can also add a start time field to specify when the auction should start. Ommitting is means that the auction will begin as soon as the Start Sale message is executed on chain.

{
"start_auction": {
        "end_time": 1716228047308,
        "uses_cw20": false,
        "coin_denom": "uandr",
        "min_bid":"500"
        "recipient":{
                "address":"<Your-wallet-address>"
                }
        }
   }

The end_time above will be in the past for you and will give an Error. Make sure to check the current epoch time in milliseconds to enter a valid end time.

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.

You can only place bids once the auction started which in our case is right away.

{
    "place_bid": {
        "token_id": "1",
        "token_address":"<cw721-contract-address>"
    }
}

Dont forget to switch wallets when bidding since the owner cannot bid on their own auctioned NFT. To switch wallets run "wallets use" then chose the wallet to bid with.

In order to bid on a token, you will need to attach funds to the message equal to the bid amount you want to place. When you run the message, you will be asked "Would you like to add funds to this message?" select yes and input the bid amount you want. An example would be 600uandr .

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.

Last updated

Additional Resources

GithubWebsite