DEV Community

Cover image for Deploying WAX Smart Contracts to Production
Ivan Montiel
Ivan Montiel

Posted on • Edited on

Deploying WAX Smart Contracts to Production

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:

cleos wallet create -n mainwallet --file ./mainnet-secrets
Enter fullscreen mode Exit fullscreen mode

Then unlock the wallet:

cleos wallet unlock -n mainwallet --password="$(cat ./mainnet-secrets)"
Enter fullscreen mode Exit fullscreen mode

And then import your key:

cleos wallet import -n mainwallet --private-key {YOUR ACTIVE_KEY PRIVATE_KEY}
Enter fullscreen mode Exit fullscreen mode

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/:

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
Enter fullscreen mode Exit fullscreen mode

Then, to create the schemas:

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
Enter fullscreen mode Exit fullscreen mode

And, to create the templates:

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
Enter fullscreen mode Exit fullscreen mode

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:

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
Enter fullscreen mode Exit fullscreen mode

Once you have updated your values, you can recompile:

rm ./build/babychicks/CMakeFiles/babychicks.dir/babychicks.obj
( cd ./build && cmake .. && make )
Enter fullscreen mode Exit fullscreen mode

Add the code permission to your account:

cleos set account permission <YOUR MAINNET ACCOUNT NAME active --add-code
Enter fullscreen mode Exit fullscreen mode

Buy some RAM for your account:

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

And finally, deploy the contract:

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

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

E-book

Get this entire WAX tutorial as an e-book on Amazon.

Additional Links

Photo by SpaceX on Unsplash

Top comments (0)