Andromeda
Search
⌃K

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.
The examples use uni-5 testnet. As of now, Juno has upgraded to uni-6. The steps of building the App remain the same.

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

Setup

Our contracts use a “ado db” contract to store code ids and a “registry” or "primitive" to store important contract addresses (such as the ado db). The addresses for both can be found in the deployed contracts section. In the contracts discussed below the references to “primitive contract” are a reference to the “registry” contract.
Since both the “registry” and “ado db” contracts have already been instantiated, all what is left for us to do is make our App.

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

{
"name":"Auction Sale",
"symbol":"AS",
"minter":{
"identifier":"juno1zkpthqsz3ud97fm6p4kxcra8ae99jgzauugyem"
}
}
Make sure to set the minter as your own address and not the one above.
As base64:
eyJuYW1lIjoiQXVjdGlvbiBTYWxlIiwic3ltYm9sIjoiQVMiLCJtaW50ZXIiOnsgICAiaWRlbnRpZmllciI6Imp1bm8xemtwdGhxc3ozdWQ5N2ZtNnA0a3hjcmE4YWU5OWpnemF1dWd5ZW0ifX0=

Auction

{}
As base64:
e30=

App

The primitive address used here might be outdated in the future. Check our deployed contracts to get the latest registry.
{
"name": "Auction App",
"app": [
{
"name": "auction",
"ado_type": "auction",
"instantiate_msg": "e30="
},
{
"name": "tokens",
"ado_type": "cw721",
"instantiate_msg": "eyJuYW1lIjoiQXVjdGlvbiBTYWxlIiwic3ltYm9sIjoiQVMiLCJtaW50ZXIiOnsgICAiaWRlbnRpZmllciI6Imp1bm8xemtwdGhxc3ozdWQ5N2ZtNnA0a3hjcmE4YWU5OWpnemF1dWd5ZW0ifX0="
}
],
"primitive_contract": "juno133fdsnvcah870exzcyxknydswyh778jfhwxzlhhgjuagh4482zpqp856dz"
}
There are several components found here. A simple name for the app, the components of the app itself and a reference to the “registry”. 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 juno testnet uni-5.
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 uni-5 testnet. The code I will use is 98. This code Id will most likely be outdated in the future. A simple way to check the latest code id for the App ADO is to query it from the ADODB using the the chain you want to use.
In the CLI, while connected to the chain of choice, run:
ado db getcodeid app
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 98 '{"name": "Auction App","app": [{"name": "auction","ado_type": "auction","instantiate_msg": "e30="},{"name": "tokens","ado_type": "cw721","instantiate_msg": "eyJuYW1lIjoiQXVjdGlvbiBTYWxlIiwic3ltYm9sIjoiQVMiLCJtaW50ZXIiOnsgICAiaWRlbnRpZmllciI6Imp1bm8xemtwdGhxc3ozdWQ5N2ZtNnA0a3hjcmE4YWU5OWpnemF1dWd5ZW0ifX0="}],"primitive_contract": "juno133fdsnvcah870exzcyxknydswyh778jfhwxzlhhgjuagh4482zpqp856dz"}'
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).

Claim Components

{
"claim_ownership":{}
}
wasm execute juno1ah8m9dpas4s4g0dkzuj485kww2ukfx28ml2p3gy6nlalaps4wcvspt249d '{"claim_ownership":{}}'

Mint Tokens

We will only mint one token to auction:
{
"mint": {
"token_id": "1",
"owner": "juno1zkpthqsz3ud97fm6p4kxcra8ae99jgzauugyem",
"extension": {
"name": "Some token",
"publisher": "juno1zkpthqsz3ud97fm6p4kxcra8ae99jgzauugyem",
"description": "A token to place in auction",
"attributes": [],
"image":"https://pic.onlinewebfonts.com/svg/img_522399.png"
}
}
}
wasm execute juno16802hcvuxjqlvl8c7j20ltgtlk5gecqw2qgrxnugc934f0n4y6rsnxtz79 '{"mint": {"token_id": "1","owner": "juno1zkpthqsz3ud97fm6p4kxcra8ae99jgzauugyem","extension": {"name": "Some token","publisher": "juno1zkpthqsz3ud97fm6p4kxcra8ae99jgzauugyem","description": "A token to place in auction", "attributes": [],"image":"https://pic.onlinewebfonts.com/svg/img_522399.png" }}}'

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": "juno1gu9dxksczas9l0gl7x2dmmum7k555mu2g724zv5839363w0p53wqweuq9h",
"token_id": "1",
"msg": "eyJzdGFydF9hdWN0aW9uIjogeyJzdGFydF90aW1lIjogMTY2NDQwMjAwMDAwMCwiZHVyYXRpb24iOiA5MDAwMDAsImNvaW5fZGVub20iOiAidWp1bm94IiwibWluX2JpZCI6IjUwMCJ9fQ=="
}
}
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": 1664402000000,
"duration": 900000,
"coin_denom": "ujunox",
"min_bid":"500"
}
}
Make sure to check the current epoch time in milliseconds to enter a valid start time.
wasm execute juno16802hcvuxjqlvl8c7j20ltgtlk5gecqw2qgrxnugc934f0n4y6rsnxtz79 '{"send_nft": {"contract": "juno1gu9dxksczas9l0gl7x2dmmum7k555mu2g724zv5839363w0p53wqweuq9h","token_id": "1","msg": "eyJzdGFydF9hdWN0aW9uIjogeyJzdGFydF90aW1lIjogMTY2NDQwMjAwMDAwMCwiZHVyYXRpb24iOiA5MDAwMDAsImNvaW5fZGVub20iOiAidWp1bm94IiwibWluX2JpZCI6IjUwMCJ9fQ=="}}'

Place Bids

Now it is time to start placing some bids on our NFT.
{
"place_bid": {
"token_id": "1",
"token_address":"juno16802hcvuxjqlvl8c7j20ltgtlk5gecqw2qgrxnugc934f0n4y6rsnxtz79"
}
}
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.
wasm execute juno1gu9dxksczas9l0gl7x2dmmum7k555mu2g724zv5839363w0p53wqweuq9h '{ "place_bid": { "token_id": "1","token_address":"juno16802hcvuxjqlvl8c7j20ltgtlk5gecqw2qgrxnugc934f0n4y6rsnxtz79"}}'
Let us query the Bids of the auction to see if they match:
{
"bids":{
"auction_id": "1",
}
}
wasm query juno1gu9dxksczas9l0gl7x2dmmum7k555mu2g724zv5839363w0p53wqweuq9h '{"bids":{"auction_id": "1"}}'

Result

- Querying contract...
{
"bids": [
{
"bidder": "juno1e53vtk7fmqzfttdvpf4a3pyx0e79wkmjzh6qsk",
"amount": "600",
"timestamp": "1664402180009179411"
},
{
"bidder": "juno19s3l3wh5a3w5dpyv6v2342aej39mwmjea8vpsn",
"amount": "2000",
"timestamp": "1664402318133803263"
}
]
}
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":"juno16802hcvuxjqlvl8c7j20ltgtlk5gecqw2qgrxnugc934f0n4y6rsnxtz79"
}
}
wasm execute juno1gu9dxksczas9l0gl7x2dmmum7k555mu2g724zv5839363w0p53wqweuq9h '{"claim": {"token_id": "1","token_address":"juno16802hcvuxjqlvl8c7j20ltgtlk5gecqw2qgrxnugc934f0n4y6rsnxtz79"}}'
Claim
You can see in the transaction details that 0.002 JUNOX were sent to our selling address which is the amount of the winning bid.

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.