NFT code-gen and deployment on Starknet.

Previously, we’ve learned deploying ERC-20 contracts to Starknet Testnet. In this tutor, we'll introduce Cairo contract code generation by Openzeppelin Wizard.

Use Wizard to generate code

The Cairo Wizard is a tools that contracts can be generated with custom features easily.We are deploying an nonfungible token with symbol “Some” which is short for “SomeToken”.And we make this contract mintable, burnable and pausable.

Cairo Code Wizard
Cairo Code Wizard

Copy or download codes to local and save as nft721.cairo, then prepare for the next step.

Set up the environment

We create a python virtual environment.And then install packages and dependencies inside the environment.

python -m venv ~/cairo_venv
source ~/cairo_venv/bin/activate

Install gmp

On Ubuntu

sudo apt install -y libgmp3-dev

On mac, you can use brew:

Install the cairo-lang python packages using:

pip install cairo-lang
pip install cairo-nile openzeppelin-cairo-contracts

Finally, run nil init to initial cairo environment which includes a local network, a testing framework, and some sample codes.

mkdir my-proj
cd my-proj
nile init

Compile the code

Compile the code with nile compile and then we can deploy to the testnet

nile deploy nft721 <your_startknet_address> --network  goerli --alias some_token

🚀 Deploying nft721
⏳ ️Deployment of 721 successfully sent at 0x064a7c6c87b170c549d10a98fe255xxx
🧾 Transaction hash: 0x1c6871776832006fdab19f58f4xxx
📦 Registering deployment as some_token in goerli.deployments.txt

As above, we deployed contract to testnet successfully.

Interact with the contract

At beginning, contracts are generated with some features like mintable, burnable and so on. We'll check it on Voyager Explorer. Firstly we mint a nft token to our own wallet.

Voyager Explorer
Voyager Explorer

After transaction has confirmed on chain, we can check that the owner of token id that match our wallet address.

Voyager Explorer
Voyager Explorer

Conclusion

With the help of Wizard, we can set up a simple erc721 with features easily.And we have learned how to deploy contracts to testnet.In the following tutorials, we’ll dive in learning Openzeppelin ’s Library.