Andromeda
Search…
⌃K

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.

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 build our project using our CLI.
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-5 testnet. I have done this and the code-id you can use is 201.

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

First, let us open the CLI by running andr in our terminal. We then need to chose the chain we want to deploy on. For this example I will be using the Juno testnet uni-5:
chain use uni-5
If this is the first time using the CLI make sure to run "wallets add <wallet-name>"
in order to create a wallet. Then go to the Juno faucet and request some tokens.
Now we can run the following in the CLI:
wasm instantiate 201 '{"name":"test","symbol":"TST","minter":"juno1zkpthqsz3ud97fm6p4kxcra8ae99jgzauugyem"}'

Mint an NFT

We will mint an NFT with token_id specified as 1.
{
"mint":{
"token_id":"1",
"owner":"juno1zkpthqsz3ud97fm6p4kxcra8ae99jgzauugyem"
}
}
wasm execute juno1nqhnl03hwhh4jtdwv6acpex7m54e3ql4sdzjvcyrgu5kgv2sc8js9kqc8c '{"mint":{"token_id":"1","owner":"juno1zkpthqsz3ud97fm6p4kxcra8ae99jgzauugyem"}}'
Mint

Instantiate Wrapped-NFT ADO.

I already have uploaded a wrapped-nft ado with code-id 117. We can instantiate it using the message below.
{
"primitive_contract":"juno133fdsnvcah870exzcyxknydswyh778jfhwxzlhhgjuagh4482zpqp856dz",
"cw721_instantiate_type":{
"new":{
"name":"test-wrap",
"symbol":"TST"
}
},
"can_unwrap": true
}
wasm instantiate 117 '{"primitive_contract":"juno133fdsnvcah870exzcyxknydswyh778jfhwxzlhhgjuagh4482zpqp856dz","cw721_instantiate_type":{"new":{"name":"test-wrap","symbol":"TST"}},"can_unwrap": true}'
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: juno1nqhnl03hwhh4jtdwv6acpex7m54e3ql4sdzjvcyrgu5kgv2sc8js9kqc8c
  • wrapped-ado: juno1wdahcdkalcl3g02sl5qnadh43le60yhndz7mx7f6syfnxce5cg3q6pwkz9
  • ado-cw721:juno1z9mzpgrksmlvg62kple37wpr0u9mvv2s725juwecxhfhxkkdfp0qahyqwz
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": "juno1wdahcdkalcl3g02sl5qnadh43le60yhndz7mx7f6syfnxce5cg3q6pwkz9",
"token_id": "1",
"msg":"eyJ3cmFwIjp7fX0="
}
}
Here the base64 encoded message is the following:
{"wrap":{}}
We run:
wasm execute juno1nqhnl03hwhh4jtdwv6acpex7m54e3ql4sdzjvcyrgu5kgv2sc8js9kqc8c '{"send_nft":{"contract":"juno1wdahcdkalcl3g02sl5qnadh43le60yhndz7mx7f6syfnxce5cg3q6pwkz9","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 juno1z9mzpgrksmlvg62kple37wpr0u9mvv2s725juwecxhfhxkkdfp0qahyqwz '{"tokens":{"owner":"juno1zkpthqsz3ud97fm6p4kxcra8ae99jgzauugyem"}}'
Result:
– Querying contract...
{
"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":"*"
}
}
}
wasm execute juno1z9mzpgrksmlvg62kple37wpr0u9mvv2s725juwecxhfhxkkdfp0qahyqwz '{"transfer_agreement":{"token_id":"1","agreement":{"amount":{"raw":{"amount":"10000","denom":"ujunox"}},"purchaser":"*"}}}'
Let us check the balances of the seller and purchaser before making the purchase to make sure that correct funds are sent:
Seller: juno1zkpthqsz3ud97fm6p4kxcra8ae99jgzauugyem
balances:
- amount: "4105237"
denom: ujunox
- amount: "20000000"
denom: uusdcx
pagination:
next_key: null
total: "0"
Buyer: juno1e53vtk7fmqzfttdvpf4a3pyx0e79wkmjzh6qsk
balances:
- amount: "9977890"
denom: ujunox
- amount: "10000000"
denom: uusdcx
pagination:
next_key: null
total: "0"
To check the balance you can run "junod query bank balances <address>" in the terminal (Not CLI).

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":"juno1e53vtk7fmqzfttdvpf4a3pyx0e79wkmjzh6qsk",
"token_id":"1"
}
}
We attach 10000 ujunox to the message:
wasm execute juno1z9mzpgrksmlvg62kple37wpr0u9mvv2s725juwecxhfhxkkdfp0qahyqwz '{"transfer_nft":{"recipient":"juno1e53vtk7fmqzfttdvpf4a3pyx0e79wkmjzh6qsk","token_id":"1"}}' --funds 10000ujunox
Let us check the balances again:
Seller
balances:
- amount: "4115237"
denom: ujunox
- amount: "20000000"
denom: uusdcx
pagination:
next_key: null
total: "0"
Buyer
balances:
- amount: "9962179"
denom: ujunox
- amount: "10000000"
denom: uusdcx
pagination:
next_key: null
total: "0"
As we can see 10000 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. 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 juno1nqhnl03hwhh4jtdwv6acpex7m54e3ql4sdzjvcyrgu5kgv2sc8js9kqc8c '{"tokens":{"owner":"juno1e53vtk7fmqzfttdvpf4a3pyx0e79wkmjzh6qsk"}}'
Result
– Querying contract...
{
"tokens": []
}
As we can see we have no tokens. Now let us unwrap our token:
{
"send_nft":{
"contract":"juno1wdahcdkalcl3g02sl5qnadh43le60yhndz7mx7f6syfnxce5cg3q6pwkz9",
"token_id":"1",
"msg":"eyJ1bndyYXAiOnt9fQo="
}
}
The base64 message is:
{"unwrap":{}}
wasm execute juno1z9mzpgrksmlvg62kple37wpr0u9mvv2s725juwecxhfhxkkdfp0qahyqwz '{"send_nft":{"contract":"juno1wdahcdkalcl3g02sl5qnadh43le60yhndz7mx7f6syfnxce5cg3q6pwkz9","token_id":"1","msg":"eyJ1bndyYXAiOnt9fQo="}}'
Now let us check again our tokens in the cw721-base contract:
wasm query juno1nqhnl03hwhh4jtdwv6acpex7m54e3ql4sdzjvcyrgu5kgv2sc8js9kqc8c '{"tokens":{"owner":"juno1e53vtk7fmqzfttdvpf4a3pyx0e79wkmjzh6qsk"}}'
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.

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.