Andromeda
Search…
Auctioning App
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.

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 “factory” contract to store code ids and a “registry” or "primitive" to store important contract addresses (such as the factory). 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 “factory” contracts have already been instantiated, all what is left for us to do is make our App.

Instantiating the App

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":"juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec"
}
}
As base64:
eyJuYW1lIjoiQXVjdGlvbiBTYWxlIiwic3ltYm9sIjoiQVMiLCJtaW50ZXIiOnsiaWRlbnRpZmllciI6Imp1bm8xOTd5NDR3NThkanF1cWtwdTh2NTZwZ3d2bTA1OGY2anN3bTBqZWMifX0===

Auction

{}
As base64:
e30=

App

{
"name": "Auction App",
"app": [
{
"name": "auction",
"ado_type": "auction",
"instantiate_msg": "e30="
},
{
"name": "tokens",
"ado_type": "cw721",
"instantiate_msg": "eyJuYW1lIjoiQXVjdGlvbiBTYWxlIiwic3ltYm9sIjoiQVMiLCJtaW50ZXIiOnsiaWRlbnRpZmllciI6Imp1bm8xOTd5NDR3NThkanF1cWtwdTh2NTZwZ3d2bTA1OGY2anN3bTBqZWMifX0="
}
],
"operators": [],
"primitive_contract": "juno144r95jrnk5erqhpuepe5mwz33e5mns7yuyhmxw7fmfx8w0duqwws9qd36x"
}
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.
First let us upload the app contract to JUNO test-net:
We dont have to repeat this step for every app we build. We can use the same code-id as for app1 (377), but for the sake of the example, I will be reuploading it as if this is my first app.
junod tx wasm store andromeda_app_contract.wasm --from juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec --chain-id=uni-3 --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y
Now let us instantiate the App using its message and the code ID (2482) we got from uploading the contract:
junod tx wasm instantiate 2482 '{"name": "Auction App","app": [{"name": "auction","ado_type": "auction","instantiate_msg": "e30="},{"name": "tokens","ado_type": "cw721","instantiate_msg": "eyJuYW1lIjoiQXVjdGlvbiBTYWxlIiwic3ltYm9sIjoiQVMiLCJtaW50ZXIiOnsiaWRlbnRpZmllciI6Imp1bm8xOTd5NDR3NThkanF1cWtwdTh2NTZwZ3d2bTA1OGY2anN3bTBqZWMifX0="}],"operators": [],"primitive_contract": "juno144r95jrnk5erqhpuepe5mwz33e5mns7yuyhmxw7fmfx8w0duqwws9qd36x"}' --label "Auction App" --from juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y --no-admin
Once again we will be using the txhash to find the transaction details in the explorer.

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":{}
}
junod tx wasm execute juno1jcuuvppz5dndm37q6rsyxyln7x02dvcljwxn3nx4lkfw9u669h0qj9gdms '{"claim_ownership":{}}' --from juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y

Mint Tokens

We will only mint one token to auction:
{
"mint": {
"token_id": "2",
"owner": "juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec",
"extension": {
"name": "Some token",
"publisher": "juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec",
"description": "A token to place in auction",
"attributes": [],
"image":"https://pic.onlinewebfonts.com/svg/img_522399.png"
}
}
}
junod tx wasm execute juno1v06demasstn9td266rf3du2dt9frcwxexsnan77x0nnamy0laeuqsqjz5w '{"mint": {"token_id": "2","owner": "juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec","extension": {"name": "Some token","publisher": "juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec","description": "A token to place in auction", "attributes": [],"image":"https://pic.onlinewebfonts.com/svg/img_522399.png" }}}' --from juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y

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": "juno1hmen67uf2ap7z4vjm3wygkzv0nspn3vpd3jcsrl0y6quxrl7w3tqu3avt3",
"token_id": "2",
"msg": "eyJzdGFydF9hdWN0aW9uIjp7InN0YXJ0X3RpbWUiOnsiYXRfaGVpZ2h0IjogMTE3NzgwMH0sImVuZF90aW1lIjp7ImF0X2hlaWdodCI6IDExNzc5NTB9LCJjb2luX2Rlbm9tIjogInVqdW5veCIsIndoaXRlbGlzdCI6IFsianVubzFuZWtkaHRqNjBzNjkyZzI4ZTRjcTV5dnBnOWFxZDR5ZWFmdTA3dCIsICJqdW5vMWVhcGFjOHZ0c3N2dXg4NXMybm4zdjA0a2s5Z21lamE1c2N5M2U3Il19fQ=="
}
}
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":{
"at_height": 1177800
},
"end_time":{
"at_height": 1177950
},
"coin_denom": "ujunox",
"whitelist": ["juno1nekdhtj60s692g28e4cq5yvpg9aqd4yeafu07t", "juno1eapac8vtssvux85s2nn3v04kk9gmeja5scy3e7"]
}
}
Make sure to check the current block heights for the testnet since using the same values above will not work.
Notice here that we included two addresses in the whitelist which we will be using to bid on the NFT.
junod tx wasm execute juno1v06demasstn9td266rf3du2dt9frcwxexsnan77x0nnamy0laeuqsqjz5w '{"send_nft": {"contract": "juno1hmen67uf2ap7z4vjm3wygkzv0nspn3vpd3jcsrl0y6quxrl7w3tqu3avt3","token_id": "2","msg": "eyJzdGFydF9hdWN0aW9uIjp7InN0YXJ0X3RpbWUiOnsiYXRfaGVpZ2h0IjogMTE3NzgwMH0sImVuZF90aW1lIjp7ImF0X2hlaWdodCI6IDExNzc5NTB9LCJjb2luX2Rlbm9tIjogInVqdW5veCIsIndoaXRlbGlzdCI6IFsianVubzFuZWtkaHRqNjBzNjkyZzI4ZTRjcTV5dnBnOWFxZDR5ZWFmdTA3dCIsICJqdW5vMWVhcGFjOHZ0c3N2dXg4NXMybm4zdjA0a2s5Z21lamE1c2N5M2U3Il19fQ=="}}' --from juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y

Place Bids

Now it is time to start placing some bids on our NFT.
{
"place_bid": {
"token_id": "2",
"token_address":"juno1v06demasstn9td266rf3du2dt9frcwxexsnan77x0nnamy0laeuqsqjz5w"
}
}
Non Whitelisted Address try to bid:
Error: rpc error: code = InvalidArgument desc = failed to execute message; message index: 0: Unauthorized: execute wasm contract failed: invalid request
Let us query the Bids of the auction to see if they match:
{
"bids":{
"auction_id": "1",
}
}
junod query wasm contract-state smart juno1hmen67uf2ap7z4vjm3wygkzv0nspn3vpd3jcsrl0y6quxrl7w3tqu3avt3 '{"bids":{"auction_id": "1"}}'

Result:

Bids:
  • amount: "1000" bidder: juno1nekdhtj60s692g28e4cq5yvpg9aqd4yeafu07t timestamp: "1660065224057442901"
  • amount: "2000" bidder: juno1eapac8vtssvux85s2nn3v04kk9gmeja5scy3e7 timestamp: "1660065268760864678"
After the Auction has concluded, it is time to claim the NFT for the buyer and Funds for the seller.

Claim

{
"claim": {
"token_id": "2",
"token_address":"juno1v06demasstn9td266rf3du2dt9frcwxexsnan77x0nnamy0laeuqsqjz5w"
}
}
junod tx wasm execute juno1hmen67uf2ap7z4vjm3wygkzv0nspn3vpd3jcsrl0y6quxrl7w3tqu3avt3 '{"claim": {"token_id": "2","token_address":"juno1v06demasstn9td266rf3du2dt9frcwxexsnan77x0nnamy0laeuqsqjz5w"}}' --from juno197y44w58djquqkpu8v56pgwvm058f6jswm0jec --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y
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.
Copy link
Outline
Defining our App
Setup
Instantiating the App
Interacting with the App