Comment on page
Wrapped-NFT App
Deploying a wrapped NFT 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.
For this example, we will be utilizing our wrapped-nft ADO to wrap a CW721-base nft and leverage the andromeda TransferAgreement functionality to sell the token. We will build our project using our CLI.
We will not build this example using the App contract.
The steps we will perform:
- 1.
- 2.Send it to wrapper ADO to have it wrapped.
- 3.Apply a TransferAgreement for the token.
- 4.Buy the token using another address.
- 5.Unwrap the token to get the original back.
We will need to use the following andromeda contracts in addition to the base-nft contract:
First we need to mint a regular nft from the cw-nft repo. To do this, we first need to clone the repo, build the contract and upload it to the chain we want to deploy on. To do so, we perform the following steps:
- Start a new project in your IDE
- In the terminal:
git clone https://github.com/CosmWasm/cw-nfts.git
cd cw-nfts
Then compile the CW721 base contract. When done, the contract .wasm file should appear in the artifacts directory.
Let us open the CLI by running
andr
in our terminal from artifacts directory. We then need to choose the chain we want to deploy on:Feel free to use any of the chains available
chain use
Then select the chain to deploy on.
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 chain's faucet to request some tokens (Usually the faucet will be in the Chain's discord).
To upload the contract, we run:
wasm upload cw721_base.wasm
The contract will be uploaded to chain and the code Id will be returned.
The instantiation message for CW721 base nft is the following:
Rust
JSON
pub struct InstantiateMsg {
pub name: String,
pub symbol: String,
pub minter: String,
}
{
"name":"wrapped token",
"symbol":"WT",
"minter":"<your-address>"
}
Now that we have our contract uploaded we can instantiate a CW721:
Use the code Id that you got when uploading the contract instead of 201.
wasm instantiate <cw721-code-id> '{"name":"test","symbol":"TST","minter":"<your-address>"}'
We will mint an NFT with token_id specified as 1.
{
"mint":{
"token_id":"1",
"owner":"<your-address>"
}
}
wasm execute <cw721-contract-address> '{"mint":{"token_id":"1","owner":"<your-address>"}}'
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 wrapped-cw721
The code Id to use will be returned.
The kernel address used here might be outdated in the future. Check our deployed contracts to get the latest kernel address.
{
"cw721_instantiate_type":{
"new":{
"name":"test-wrap",
"symbol":"TST"
}
},
"can_unwrap": true,
"kernel_address":"andr159llw7xkpt20llxqmjegsegfn548q5l6jr2x7rh7sy7sal39syfs3tlvmm"
}
wasm instantiate <wrapped-code-id> '{"cw721_instantiate_type":{"new":{"name":"test-wrap","symbol":"TST"}},"can_unwrap": true,"kernel_address":"andr159llw7xkpt20llxqmjegsegfn548q5l6jr2x7rh7sy7sal39syfs3tlvmm"}'
When we instantiate the wrapped-nft contract, we specified the cw721 type as new which means that we have also instantiated an andromeda cw721 contract.
{
"send_nft": {
"contract": "<wrapped-NFT-contract-address>",
"token_id": "1",
"msg":"eyJ3cmFwIjp7fX0="
}
}
Here the base64 encoded message is the following:
{"wrap":{}}
We run:
wasm execute <cw721-contract-address> '{"send_nft":{"contract":"<wrapped-NFT-contract-address>","token_id":"1","msg":"eyJ3cmFwIjp7fX0="}}'
We have wrapped the nft, this means that the andromeda cw721 should have minted a new token for us. Let us check by querying our tokens in the andromeda nft contract.
wasm query <andromeda-cw721-contract-address> '{"tokens":{"owner":"<your-owner-address>"}}'
Result:
– Querying contract...
{
"tokens": [
"1"
]
}
Now since we have our andromeda NFT, we want to add a transferagreement to it in order to sell the token.
We have specified the purchaser as "*" which means any address is allowed to purchase the token.
{
"transfer_agreement":{
"token_id":"1",
"agreement":{
"amount":{
"raw":{
"amount":"100000",
"denom":"uandr"
}
},
"purchaser":"*"
}
}
}
wasm execute <andromeda-cw721-contract-address> '{"transfer_agreement":{"token_id":"1","agreement":{"amount":{"raw":{"amount":"10000","denom":"uandr"}},"purchaser":"*"}}}'
If not familiar with our TransferAgreement message, it allows any buyer to transfer the token to themselves as long as the required funds (Price we set) is attached to the message.
{
"transfer_nft":{
"recipient":"<any-recipient-address>",
"token_id":"1"
}
}
We attach 10000 uandr to the message:
wasm execute <andromeda-cw721-contract-address> '{"transfer_nft":{"recipient":"<any-recipient-address>","token_id":"1"}}' --funds 10000uandr
The NFT will be transfered to the recipient and the funds sent to the seller.
We have minted a cw721-base nft, wrapped it using the andromeda ADOs and sold it using the custom TransferAgreement. Now we will unwrap the token and get the original back.
The buyer of the token is now the owner, so he would be unwrapping the token. Make sure you are using the new owner wallet to run the next message.
Let us see our tokens first in the cw721-base contract:
wasm query <cw721-base-contract-address> '{"tokens":{"owner":"<owner-address>"}}'
Result
– Querying contract...
{
"tokens": []
}
As we can see we have no tokens. Now let us unwrap our token:
{
"send_nft":{
"contract":"<wrapped-NFT-contract-address>",
"token_id":"1",
"msg":"eyJ1bndyYXAiOnt9fQo="
}
}
The base64 message is:
{"unwrap":{}}
wasm execute <andromeda-cw721-contract-address> '{"send_nft":{"contract":"<wrapped-NFT-contract-address>","token_id":"1","msg":"eyJ1bndyYXAiOnt9fQo="}}'
Now let us check again our tokens in the cw721-base contract:
wasm query <cw721-base-contract-address> '{"tokens":{"owner":"<nft-owner-address>"}}'
Result
– Querying contract...
{
"tokens": [
"1"
]
}
As we can see, when we unwrapped the token, the wrapped token is removed and the original token is back in our address.
The Andromeda wrapped ADO is one of many custom contracts that the Andromeda team has built to allow use cases such as the one we have demonstrated above. We can wrap tokens to leverage any of the functionalities that Andromeda has built. For example we can wrap a token and sell it in an auction, offers, and even use the staking nft to allow staking of these tokens. The possibilites are endless and only limited by the user's imagination.
Last modified 2h ago