Deploying WAX Smart Contracts to Production
Tags: wax, blockchain, tutorial
Published: 2023-08-06 23:12:11

## Introduction

Throughout these tutorials, we’ve created our AtomicAssets collection, schema, templates, and deployed a Smart Contract to the testnet that can interact with our AtomicAssets. In this section, we are going to go through the steps required to deploy to production.

We will need to do a few things to launch our WAX NFT to the mainnet:

- Create a mainnet WAX Account
- Set up our mainnet wallet
- Create our AtomicAssets on the Mainnet
- Update our Smart Contract
- And finally, deploy our Smart Contract to production.

## Create a mainnet WAX Account

When we created our WAX Account on the testnet, we were able to use the https://waxsweden.org/create-testnet-account/ site to create a new account. On mainnet, you will need to first create an account through your main WAX Account. See https://eos-amsterdam.medium.com/how-to-create-a-new-wax-account-7a23cf315ac0 for more information.

## Setup Your mainnet Wallet

Now that you have a key-pair created for your new WAX account, you will want to import it into your CLI and Anchor wallets.

For the CLI, you can import like we did for the original testwallet we made:

```sh
cleos wallet create -n mainwallet --file ./mainnet-secrets
```

Then unlock the wallet:

```sh
cleos wallet unlock -n mainwallet --password="$(cat ./mainnet-secrets)"
```

And then import your key:

```sh
cleos wallet import -n mainwallet --private-key {YOUR ACTIVE_KEY PRIVATE_KEY}
```

Now you will be able to use your mainwallet to deploy to the mainnet.

Adding to Anchor is the same as we did with the testnet. Simply switch the WAX mainnet blockchain, and import your Private Key.

## Create Your mainnet AtomicAsset Collection

When we created our testnet AtomicAsset collections, we wrote them to be flexible enough that we could reuse the same commands for the mainnet. To create the collection, we will use a public mainnet endpoint [`https://wax.pink.gg/`](https://wax.pink.gg/):

```sh
WAX_ACCOUNT={YOUR MAINNET ACCOUNT NAME} \
WAX_PRIVATE_KEY="<YOUR WAX ACCOUNT ACTIVE PRIVATE KEY>" \
WAX_ENDPOINT=https://wax.pink.gg \
  node ./src/000-create-collection.js
```

Then, to create the schemas:

```sh
WAX_ACCOUNT={YOUR MAINNET ACCOUNT NAME} \
WAX_PRIVATE_KEY="<YOUR WAX ACCOUNT ACTIVE PRIVATE KEY>" \
WAX_ENDPOINT="https://wax.pink.gg" \
  node ./src/010-create-chick-egg-schema.js

WAX_ACCOUNT={YOUR MAINNET ACCOUNT NAME} \
WAX_PRIVATE_KEY="<YOUR WAX ACCOUNT ACTIVE PRIVATE KEY>" \
WAX_ENDPOINT="https://wax.pink.gg" \
  node ./src/020-create-baby-chick-schema.js
```

And, to create the templates:

```sh
WAX_ACCOUNT={YOUR MAINNET ACCOUNT NAME} \
WAX_PRIVATE_KEY="<YOUR WAX ACCOUNT ACTIVE PRIVATE KEY>" \
WAX_ENDPOINT=<https://wax.pink.gg> \
  node ./src/030-create-chick-egg-templates.js

WAX_ACCOUNT={YOUR MAINNET ACCOUNT NAME} \
WAX_PRIVATE_KEY="<YOUR WAX ACCOUNT ACTIVE PRIVATE KEY>" \
WAX_ENDPOINT=<https://wax.pink.gg> \
  node ./src/040-create-baby-chick-templates.js
```

## Updating Our Smart Contract

Once you have your AtomicAssets created, go to AtomicHub, and find the template ids for the mainnet templates, and update them in the babychick header:

```cpp
static constexpr name EGG_SCHEMA_NAME = name("chickegg");
static constexpr name BABY_CHICK_SCHEMA_NAME = name("babychick");
static constexpr uint32_t EGG_TEMPLATE_ID = -1; // Set to the mainnet id
static constexpr uint32_t EPIC_TEMPLATE_ID = -1; // Set to the mainnet id
static constexpr uint32_t RARE_TEMPLATE_ID = -1; // Set to the mainnet id
static constexpr uint32_t COMMON_TEMPLATE_ID = -1; // Set to the mainnet id
```

Once you have updated your values, you can recompile:

```sh
rm ./build/babychicks/CMakeFiles/babychicks.dir/babychicks.obj
( cd ./build && cmake .. && make )
```

Add the `code` permission to your account:

```sh
cleos set account permission <YOUR MAINNET ACCOUNT NAME active --add-code
```

Buy some RAM for your account:

```sh
cleos -v -u https://wax.pink.gg \
  system buyram <YOUR MAINNET ACCOUNT NAME> waxcourse123 "500" --kbytes \
  -p <YOUR MAINNET ACCOUNT NAME>@active
```

And finally, deploy the contract:

```sh
cleos -v -u https://wax.pink.gg set contract <YOUR MAINNET ACCOUNT NAME> ./babychicks/build/babychicks -p <YOUR MAINNET ACCOUNT NAME>@active
```

## Conclusion

And with that, we have successfully deployed a fully functional contract to the production mainnet. This Smart Contract leverages the best-practices of using AtomicAssets to create a fully featured NFT on the WAX blockchain that anyone can interact with. It also provides interactivity, letting users purchase and hatch their NFTs without any other third-party.

This shows just a small set of the awesome experiences that can be built on the WAX Blockchain, we can’t wait to see what you build.

Next post: [Final Thoughts on WAX Smart Contracts](https://dev.to/idmontie/final-thoughts-on-wax-smart-contracts-40ak)

## E-book

Get this entire WAX tutorial as an [e-book on Amazon](https://amzn.to/3ZjwaK7).

## Additional Links

Photo by [SpaceX](https://unsplash.com/@spacex?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/photos/-p-KCm6xB9I?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)