Andromeda
Search…
Wrapped-NFT 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 utilizing our wrapped-nft ADO to wrap a cw721-base nft and leverage the andromeda TransferAgreement functionality to sell the token.
We will not build this example using the App contract.
The steps we will perform:
  1. 1.
    Mint a token using the cw721-base contract found in cw-nfts repo.
  2. 2.
    Send it to wrapper ADO to have it wrapped.
  3. 3.
    Apply a TransferAgreement for the token.
  4. 4.
    Buy the token using another address.
  5. 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:

Instantiating the CW-721 base NFT

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 juno uni-3 testnet. I have done this and the code-id you can use is 2240.

Instantiate

The instantiation message for cw-721 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":"juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll"
}

Instantiate

junod tx wasm instantiate 2240 '{"name":"test","symbol":"TST","minter":"juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll"}' --label "wrapped" --from juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y --no-admin

Mint an NFT

We will mint an NFT with token_id specified as 1.
{
"mint":{
"token_id":"1",
"owner":"juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll"
}
}
junod tx wasm execute juno134hgkjxzftmttgg5w5v79wmm0mdwn0y04s5pyy4lwekkk8fsucqsk3xtqc '{"mint":{"token_id":"1","owner":"juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll"}}' --from juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y
Mint

Instantiate Wrapped-NFT ADO.

We already have uploaded a wrapped-nft ado with code-id 2196. We can instantiate it using the message below.
{
"primitive_contract":"juno144r95jrnk5erqhpuepe5mwz33e5mns7yuyhmxw7fmfx8w0duqwws9qd36x",
"cw721_instantiate_type":{
"new":{
"name":"test-wrap",
"symbol":"TST"
}
},
"can_unwrap": true
}
junod tx wasm instantiate 2196 '{"primitive_contract":"juno144r95jrnk5erqhpuepe5mwz33e5mns7yuyhmxw7fmfx8w0duqwws9qd36x","cw721_instantiate_type":{"new":{"name":"test-wrap","symbol":"TST"}},"can_unwrap": true}' --label "wrapped-nft" --from juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y --no-admin
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.

Contracts:

Let us list the contracts thus far to avoid confusion:
  • cw721-base: juno134hgkjxzftmttgg5w5v79wmm0mdwn0y04s5pyy4lwekkk8fsucqsk3xtqc
  • wrapped-ado: juno1u4jg78rt9ruulptgk5xluz3r2gpt9uurnuvv9h6zedszk6y6qu4qwp43jj
  • ado-cw721:juno1q2m6f79j6wpcfw7v4lzlwe5x5u0utptjd28lsvdtl6pslwhur8yqzyvyzj
Now we have everything set up, we can send the token we minted earlier to get wrapped by our ADO.

Wrap the NFT

{
"send_nft": {
"contract": "juno1u4jg78rt9ruulptgk5xluz3r2gpt9uurnuvv9h6zedszk6y6qu4qwp43jj",
"token_id": "1",
"msg":"eyJ3cmFwIjp7fX0="
}
}
Here the base64 encoded message is the following:
{"wrap":{}}
We run:
junod tx wasm execute juno134hgkjxzftmttgg5w5v79wmm0mdwn0y04s5pyy4lwekkk8fsucqsk3xtqc '{"send_nft":{"contract":"juno1u4jg78rt9ruulptgk5xluz3r2gpt9uurnuvv9h6zedszk6y6qu4qwp43jj","token_id":"1","msg":"eyJ3cmFwIjp7fX0="}}' --from juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y
We have wrapped the nft, this means that the andromeda cw721 should have minted a new token for us. Let us check by querying my tokens in the andromeda nft contract.
junod query wasm contract-state smart juno1q2m6f79j6wpcfw7v4lzlwe5x5u0utptjd28lsvdtl6pslwhur8yqzyvyzj '{"tokens":{"owner":"juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll"}}'
Result:
data:
tokens:
-"1"

TransferAgreement

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":"ujunox"
}
},
"purchaser":"*"
}
}
}
junod tx wasm execute juno1q2m6f79j6wpcfw7v4lzlwe5x5u0utptjd28lsvdtl6pslwhur8yqzyvyzj '{"transfer_agreement":{"token_id":"1","agreement":{"amount":{"raw":{"amount":"100000","denom":"ujunox"}},"purchaser":"*"}}}' --from juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y
Let us query the balances of the seller and purchaser before making the purchase to make sure that correct funds are sent:
Seller
juno query bank balances juno1hfngwh4f53smthvqde32y07rjcezdsnlztxtll
Result:
amount: "10492823" denom: ujunox
Buyer
junod query bank balances juno179rfqj225d5crspna2uujau8003eqtdq2q68hh
Result:
amount: "1228107361" denom: ujunox

Buy the NFT

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":"juno179rfqj225d5crspna2uujau8003eqtdq2q68hh",
"token_id":"1"
}
}
We attach 100000 ujunox to the message:
junod tx wasm execute juno1q2m6f79j6wpcfw7v4lzlwe5x5u0utptjd28lsvdtl6pslwhur8yqzyvyzj '{"transfer_nft":{"recipient":"juno179rfqj225d5crspna2uujau8003eqtdq2q68hh","token_id":"1"}}' --from juno179rfqj225d5crspna2uujau8003eqtdq2q68hh --amount 100000ujunox --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y
Let us check the balances again:
Seller: 10592823ujunox
Buyer: 1227984518ujunox
As we can see 100000 ujunox have been transfered and the token is now owned by the buyer address.

Unwrap the Token

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.
Let us see our tokens first in the cw721-base contract:
junod query wasm contract-state smart juno134hgkjxzftmttgg5w5v79wmm0mdwn0y04s5pyy4lwekkk8fsucqsk3xtqc '{"tokens":{"owner":"juno179rfqj225d5crspna2uujau8003eqtdq2q68hh"}}'
Result: tokens: [].
As we can see we have no tokens. Now let us unwrap our token:
{
"send_nft":{
"contract":"juno1u4jg78rt9ruulptgk5xluz3r2gpt9uurnuvv9h6zedszk6y6qu4qwp43jj",
"token_id":"1",
"msg":"eyJ1bndyYXAiOnt9fQo="
}
}
The base64 message is:
{"unwrap":{}}
junod tx wasm execute juno1q2m6f79j6wpcfw7v4lzlwe5x5u0utptjd28lsvdtl6pslwhur8yqzyvyzj '{"send_nft":{"contract":"juno1u4jg78rt9ruulptgk5xluz3r2gpt9uurnuvv9h6zedszk6y6qu4qwp43jj","token_id":"1","msg":"eyJ1bndyYXAiOnt9fQo="}}' --from juno179rfqj225d5crspna2uujau8003eqtdq2q68hh --gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -b block -y
Now let us check again our tokens in the cw721-base contract:
junod query wasm contract-state smart juno134hgkjxzftmttgg5w5v79wmm0mdwn0y04s5pyy4lwekkk8fsucqsk3xtqc '{"tokens":{"owner":"juno179rfqj225d5crspna2uujau8003eqtdq2q68hh"}}'
Result:
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.

Conclusion

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.
Copy link
Outline
Defining our App
Instantiating the CW-721 base NFT
Instantiate
Instantiate Wrapped-NFT ADO.
TransferAgreement
Buy the NFT
Unwrap the Token
Conclusion