Using CLI to Interact with Apps
Last updated
Last updated
In this section, we will be taking a look on how we can use the Andromeda CLI to interact with the apps we have built. We use the CLI since the web-app only allows execution of messages on currently owned ADOs. This means you can only interact with an ADO if you are the owner.
In most cases, the owner of an ADO is not allowed to bid/buy anything they put up for sale, so we need to interact with these apps using different addresses representing buyers/users wanting to interact with your apps.
We have a full section in our docs covering the CLI and it's functionality. If interested in learning more about it then check out the Andromeda CLI docs.
Make sure to build some apps using our ADO Builder examples before jumping into this section.
The first thing you will need to do is download the CLI and create a new address.
We will download the Andromeda CLI through npm. To check if you have npm already installed, run:
If the npm version appears,then you are good to go. If not, you can easily download it from here.
To download the Andromeda CLI run the following command in your terminal:
Then run "andr" to open the CLI:
To connect to a chain run:
Connect to the chain that you have built your apps on.
Select the testnet you want to connect to.
If you already have a wallet that needs to be imported to the CLI, go to "Recovering a Wallet" section.
To create a new wallet run:
You will be prompted to select a name and password for the wallet. Once selected, you will get your seed phrase which is compromised of 24 words. This seed phrase is the only way an address can be recovered so make sure to keep it somewhere safely.
The 'private key'/'seed phrase' is always shown once. Please make sure to write it down and store it somewhere safe.
After saving your seed phrase, you will be asked to input some of the words.
Finally run:
The wallet you created should appear with the name and address.
If you forget your password or lose your key, or you would like to use your key in another place, you can recover your key by using the --recover
flag.
The following example will recover a key with the seed phrase and store it in the local keystore with the name test:
You'll be asked to enter and repeat the new password for your key, and enter the seed phrase. Then you get your key back.
Now that you have a wallet set up, you can start executing some messages on your apps.
If you have built our ADO Builder examples, then you already know how to setup a custom auction for NFTs. In the examples we covered, we always stopped after the auction set up. Now, we will be buying some NFTs as a user and checking that everything we set up worked as intended.
Before we continue, you will need to build an Auction app to use. You can follow the "Creating your First NFT Auction House".
If you have already built the app, you don't have to do it again.
In order to bid on an NFT in an auction, a sale on the NFT must be ongoing. In the last steps of our example, we started an auction sale on an NFT specifying the start time, duration, and other properties. Make sure that there is an ongoing auction on the NFT before attempting to bid.
If the auction you started when following the example has expired, then execute the Claim execute message of the auction on the NFT. Once claimed, you can start a new auction on the NFT. Alternatively, you can mint a new NFT and start an auction on it.
First thing we need to do is get the contract address of the ADO we want to execute on. In our case, we want to bid on an NFT meaning we need to execute on the Auction component in the app. You can get the address of the Auction component from the assets page:
Now in the CLI, we run:
This will get the list of execute messges for an auction for you to choose from. Since we want to place a bid on an NFT, select Place Bid. Once selected, you will be prompted to fill in the messages fields. For placing a bid, you have to specify the following:
The contract address of the CW721 ADO used. We get this from the assets page.
Token Id of the NFT to bid on.
The amount of funds to attach. This will be the amount of the bid.
In the image below, I place a 1000 uandr bid on the NFT with token Id 1:
Feel free to create many wallets and bid multiple times on the same NFT.
Now we wait for the auction to end. In the meantime, let us check some balances to make sure that the funds were allocated correctly when we claim the NFT later on.
To check the balance of an address we can run:
Let us check the balance of the seller (Connected wallet on the web-app):
When the expiry of the auction is reached, claim the NFT:
Let's get the balance of the seller once more:
As you can see, the balance of the seller has increased by 1000uandr exactly after the NFT was claimed. Now let us check the owner of the NFT that was sold. We can do that by performing a query on the CW721 ADO in our app.
There are two main types of messages for an ADO after it has been published:
Execute Messages: Used to perform some action on an ADO. We have already seen how these messages work.
Query Messages: Used to fetch information on an ADO. Queries do not cost any fees.
The list of execute and query messges available for each ADO can be found in the ADO's own documentation page.
To run a query on an ADO, we run the following in the CLI:
I want to check the owner of the NFT I sold to make sure that it was transferred to the buyer:
The owner is the same as the buyer, so I can be sure that the app has acted as expected.
You can perform similar steps to interact with any apps you build. Here is a list of what you can do for the other apps:
Bid on the NFTs
Check the change in balances of the buyer, seller, and recipients of the royalties
Check using a query the new owner of the NFT
Buy NFTs
Check the change in balances of the buyer, seller, and recipients of the taxes
Check using a query the new owner of the NFT
Buy NFTs from the crowdfund
Check the change in balances of the buyer, seller
Check the balances of the addresses that received the funds from the Crowdfund