Deploy our contract and play with it
1. Generate and test the schema
- Define the schema in
src/bin/schema.rs
We should generate JSON Schemas that serve as a guide for anyone trying to use the contract.
use std::env::current_dir;
use std::fs::create_dir_all;
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use aura_nft::msg::{ConfigResponse, ExecuteMsg, InstantiateMsg, QueryMsg};
fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();
export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(ConfigResponse), &out_dir);
}
- Generate the new schema.
cd cw721-dapp
cargo schema
The output will be look like this:
├── schema/
│ ├── config_response.json
│ ├── execute_msg.json
│ ├── instantiate_msg.json
│ ├── query_msg.json
2. Build and deploy contract
Build and deploy contract
Before your contract can be used, it has to be compiled, and then stored on chain.
- Store
cw721_base
contract
As I said before, we use cw721_base
contract to create instances then interact with it to generate NFT. You can clone cw721_base
at link. Firstly, you change current workspace into contract/cw721-base
, then compile contract:
RUSTFLAGS='-C link-arg=-s' cargo wasm
Then create Beaker.toml
file with format.
When successful, will be have file cw721_base.wasm
in folder target/wasm32-unknown-unknown/release
. We will deploy this into mainnet.
beaker wasm store-code cw721_base --signer-account signer --network euphoria --no-wasm-opt --gas 8000ueaura --gas-limit 8000000
After running the above bash command, if successful, your terminal will print something similar to this:
Code stored successfully!! 🎉
+
├── code_id: 310
└── instantiate_permission: –
For this, I have uploaded the code of cw721_base (version 0.15.0) to Aura testnet with code_id of 230. You can use this code_id or customize your own cw721_base by yourself.
- Deploy contract
beaker wasm deploy cw721-factory --raw '{"cw20_address":"aura1yj9f4ktaja603dvrjq4f526y5ssscslhd85k3cx0a7z7z5pkp64qxgh3ql", "max_tokens":100, "name":"Hola Amigo", "owner":"aura10dyct5559d7c767mkmjmzh022fq52ara95vdje", "symbol":"ANT", "token_code_id": 230, "token_uri": "https://res.cloudinary.com/stargaze/image/upload/w_700/qg9ch3mcfp2bbm09uw7q.mp4", "unit_price": "13"}' --signer-account aloha --network euphoria --gas 35000ueaura --gas-limit 8000000 --label Aura_NFT
After running the above bash command, if successful, your terminal will print something similar to this:
Code stored successfully!! 🎉
+
├── code_id: 605
└── instantiate_permission: –
Contract instantiated successfully!! 🎉
+
├── label: default
├── contract_address: aura1hhl3a2vmuq9skhwd4m9r9yzgml5dt2sgfvjpmh0x0g4vct03h0hs5lgmjh
├── code_id: 605
├── creator: aura10dyct5559d7c767mkmjmzh022fq52ara95vdje
└── admin: -
After successful deployment, you can see result has been written into .beaker
.
3. Now, let's play with it
1. Mint an NFT
Now let's begin minting NFT. All of things we need to do is transfer cw20 token to cw721 contract address.
#!/bin/bash
beaker wasm execute cw20-factory-token --raw '{"send": {"contract":"aura1hhl3a2vmuq9skhwd4m9r9yzgml5dt2sgfvjpmh0x0g4vct03h0hs5lgmjh", "amount":"13", "msg": ""}}' --signer-account signer --network serenity --gas-limit 800000 --gas 8000uaura
After running the above bash command, if successful, your terminal will print something similar to this:
Contract executed successfully!! 🎉
+
├── label: default
└── contract_address: aura1gnyrkvfu4y2jg3yc6p7u64amfgexq64w7qld8fz58ln4j7hr0f4q7jzdq0
2. Query Config state of our contract
You can query config state through beaker:
beaker wasm query cw721-factory --raw '{"get_config": {}}' --network serenity
After running the above bash command, if successful, your terminal will print something similar to this:
Succesffuly executed query!! 🎉
+
├── label: default
├── contract_address: aura1hhl3a2vmuq9skhwd4m9r9yzgml5dt2sgfvjpmh0x0g4vct03h0hs5lgmjh
└── data:
{
"owner": "aura10dyct5559d7c767mkmjmzh022fq52ara95vdje",
"cw20_address": "aura1gnyrkvfu4y2jg3yc6p7u64amfgexq64w7qld8fz58ln4j7hr0f4q7jzdq0",
"cw721_address": "aura1rc6xzpkhkkj3ap328wkge058u32u5y0vfukyljm9rq9pwed8n60qak6qug",
"max_tokens": 100,
"unit_price": "13",
"name": "Hola Amigo",
"symbol": "ANT",
"token_uri": "https://res.cloudinary.com/stargaze/image/upload/w_700/qg9ch3mcfp2bbm09uw7q.mp4",
"extension": null,
"unused_token_id": 1
}
3. Query NFT info
For query NFT info, you need add cw721 instance has query before into .beaker file, similar like this :
{
"serenity": {
"cw721-factory": {
"code_id": 605,
"addresses": {
"cw721_factory": "aura1j5srdawxwej8tk3cw8026vyf3e9phgd244g6pre63y64qjlxszps3fpvzn",
"default": "aura1hhl3a2vmuq9skhwd4m9r9yzgml5dt2sgfvjpmh0x0g4vct03h0hs5lgmjh",
"cw721": "aura1rc6xzpkhkkj3ap328wkge058u32u5y0vfukyljm9rq9pwed8n60qak6qug"
},
"proposal": {
"store_code": null
}
}
}
}
Then use beaker cli to query info like this:
beaker wasm query cw721-factory --raw '{"all_tokens": {}}' --network serenity --label cw721
beaker wasm query cw721-factory --raw '{"all_nft_info": {"token_id": "0"}}' --network serenity --label cw721
After running the above bash command, if successful, your terminal will print something similar to this:
Succesffuly executed query!! 🎉
+
├── label: cw721
├── contract_address: aura1rc6xzpkhkkj3ap328wkge058u32u5y0vfukyljm9rq9pwed8n60qak6qug
└── data:
{
"tokens": [
"0"
]
}
Succesffuly executed query!! 🎉
+
├── label: cw721
├── contract_address: aura1rc6xzpkhkkj3ap328wkge058u32u5y0vfukyljm9rq9pwed8n60qak6qug
└── data:
{
"access": {
"owner": "aura10dyct5559d7c767mkmjmzh022fq52ara95vdje",
"approvals": []
},
"info": {
"token_uri": "https://res.cloudinary.com/stargaze/image/upload/w_700/qg9ch3mcfp2bbm09uw7q.mp4",
"extension": null
}
}
Thank you very much!
Well, we've reached the end of the amazing CosmWasm tutorial series. We'd like to thank you for following our story so far. If this tutorial has helped even just one person it makes it so worth it.