Auctioning App

Deploying an auctioning App using the Andromeda CLI.

If unfimailar 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.

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

For this example, we will be building a simple auction app. 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 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.

The primitive_contract and modules fields can be omitted without affecting the result.

Token

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":"andr159llw7xkpt20llxqmjegsegfn548q5l6jr2x7rh7sy7sal39syfs3tlvmm"
}

As base64:

eyJyYXRlcyI6W3sicmF0ZSI6eyJwZXJjZW50Ijp7InBlcmNlbnQiOiIwLjEifX0sImlzX2FkZGl0aXZlIjpmYWxzZSwicmVjaXBpZW50cyI6W3siYWRkcmVzcyI6ImFuZHIxY3A5dnh2cGxnamY1MDh0aHRhY3Z4ZWg2cXhxc3g2N2dzZXFjZDUifV19XSwia2VybmVsX2FkZHJlc3MiOiJhbmRyMTU5bGx3N3hrcHQyMGxseHFtamVnc2VnZm41NDhxNWw2anIyeDdyaDdzeTdzYWwzOXN5ZnMzdGx2bW0ifQ==

Auction

{
"kernel_address":"andr159llw7xkpt20llxqmjegsegfn548q5l6jr2x7rh7sy7sal39syfs3tlvmm"
}

As base64:

eyJrZXJuZWxfYWRkcmVzcyI6ImFuZHIxNTlsbHc3eGtwdDIwbGx4cW1qZWdzZWdmbjU0OHE1bDZqcjJ4N3JoN3N5N3NhbDM5c3lmczN0bHZtbSJ9

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":"eyJrZXJuZWxfYWRkcmVzcyI6ImFuZHIxNTlsbHc3eGtwdDIwbGx4cW1qZWdzZWdmbjU0OHE1bDZqcjJ4N3JoN3N5N3NhbDM5c3lmczN0bHZtbSJ9"
       }
     },
    {
      "name": "tokens",
      "ado_type": "cw721",
      "component_type":{
      "new":"eyJuYW1lIjoiQXVjdGlvbk5GVHMiLCJzeW1ib2wiOiJBTkZUIiwibWludGVyIjoiYW5kcjFnMGMweThwcmtod3JuZmZydzhhZndkcGx2OXdtNXdndDloZHY3dSIsImtlcm5lbF9hZGRyZXNzIjoiYW5kcjE1OWxsdzd4a3B0MjBsbHhxbWplZ3NlZ2ZuNTQ4cTVsNmpyMng3cmg3c3k3c2FsMzlzeWZzM3Rsdm1tIn0="
       }
    }
  ],
  "kernel_address":"andr159llw7xkpt20llxqmjegsegfn548q5l6jr2x7rh7sy7sal39syfs3tlvmm"
  }

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:

ado db 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":"eyJrZXJuZWxfYWRkcmVzcyI6ImFuZHIxNTlsbHc3eGtwdDIwbGx4cW1qZWdzZWdmbjU0OHE1bDZqcjJ4N3JoN3N5N3NhbDM5c3lmczN0bHZtbSJ9"}},{"name": "tokens","ado_type": "cw721","component_type":{"new":"eyJuYW1lIjoiQXVjdGlvbk5GVHMiLCJzeW1ib2wiOiJBTkZUIiwibWludGVyIjoiYW5kcjFnMGMweThwcmtod3JuZmZydzhhZndkcGx2OXdtNXdndDloZHY3dSIsImtlcm5lbF9hZGRyZXNzIjoiYW5kcjE1OWxsdzd4a3B0MjBsbHhxbWplZ3NlZ2ZuNTQ4cTVsNmpyMng3cmg3c3k3c2FsMzlzeWZzM3Rsdm1tIn0="}}],"kernel_address":"andr159llw7xkpt20llxqmjegsegfn548q5l6jr2x7rh7sy7sal39syfs3tlvmm"}'

Transaction

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

Interacting with the App

Andromeda contracts assign the original instantiator as contract owners. Due to how instantiation via a submessage operates in CosmWasm contracts, we must claim ownership of the components in order to execute messages that have authorization restrictions (owner restricted).

You can also use proxy messages to execute through the app ADO itself, but for these examples we will be claiming ownership.

Claim Components

{
"claim_ownership":{}
}
wasm execute <app-contract-address> '{"claim_ownership":{}}' 

Claim Components

Mint Tokens

We will only mint one token 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":"andr1g0c0y8prkhwrnffrw8afwdplv9wm5wgt9hdv7u","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": "eyJzdGFydF9hdWN0aW9uIjogeyJzdGFydF90aW1lIjogMTcwMDgzODU1MDE0MSwiZHVyYXRpb24iOiA2MDAwMDAsImNvaW5fZGVub20iOiAidWFuZHIiLCJtaW5fYmlkIjoiNTAwIn19"
    }
}

The attached message is a start_auction message to start the auction when the NFT is sent (When start_time is reached).

{
"start_auction": {
        "start_time": 1700838550141,
        "duration": 600000,
        "coin_denom": "uandr",
        "min_bid":"500"
        }
   }

The start_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 start 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 start_time has been reached.

{
    "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": "andr14pmn28jyqgphd5wv0z28ppxe5ryeraqqgqfr2v",
      "amount": "600",
      "timestamp": "1700838569272888963"
    },
    {
      "bidder": "andr1f9q5dhg5q434jyjes002fvkcuk062tnt0wdzl8",
      "amount": "2000",
      "timestamp": "1700838611450163665"
    }
  ]
}

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

Claim

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