Interacting with the Hatch Action
Tags: cpp, wax, blockchain, tutorial
Published: 2023-08-06 23:08:41

## Introduction

We’ve implemented our new contract functionality for hatching a BabyChick NFT from a ChickEgg NFT. Now we’ll deploy our contract to the testnet and interact with it to hatch our own NFT on the testnet.

## Deploying Our Contract

We can deploy our now updated contract to the testnet. As before, even through we are deploying an updated contract to our account, any tables and data that existed before will not be destroyed in this process.

Let’s unlock our wallet:

```sh
cd /wax
cleos wallet open -n testwallet
cleos wallet unlock -n testwallet --password="$(cat ./secrets)"
```

No we will deploy our contract:

```sh
cleos -v -u https://testnet.wax.pink.gg set contract waxcourse123 ./babychicks/build/babychicks -p waxcourse123@active
```

This command may give you an error if you do not have enough RAM purchased for your account to use:

```sh
Reading WASM from /wax/babychicks/build/babychicks/guestbook.wasm...
Publishing contract...
Error 3080001: Account using more than allotted RAM usage
Error Details:
account waxcourse123 has insufficient ram; needs 81572 bytes has 9592 bytes
Stack Trace:
resource_limits.cpp:235 verify_account_ram_usage
```

In this case, we need to buy RAM for our account. This is a useful command to have bookmarked:

```sh
# Remember to change waxcourse123 to your account name
cleos -v -u https://testnet.wax.pink.gg \
  system buyram waxcourse123 waxcourse123 "500" --kbytes \
  -p waxcourse123@active
```

If everything succeeded, you will see similar output to the following:

![Successful result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1fk5hiqpe52zvkbe81n8.png)

In the next section, we’ll send the contract a ChickEgg NFT to test it.

## Hatching an Egg

We’ll use AtomicHub for the Wax Testnet to test out our new contract functionality.

Here, we’ve minted and transferred a BabyChick to the account `darkemblemts`. You’ll want to create a separate account using https://waxsweden.org/create-testnet-account/ to test non-admin functionality and ensure your Smart Contract code works correctly in the context of non-admin users.


![BabyChick NFT on AtomicHub](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gb46lwdk06zf8t66a7mc.png)


Scroll down a bit and you will see a section that says “Transfer”:


![Transfer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eww5qtatai1ql53epznu.png)


Fill in the details for the transfer: To `waxcourse123` and Memo `hatch`:

![hatch memo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dbaedei0jpplkpcy78la.png)

Once you confirm through Anchor, you will see this message:

![AtomicHub Success](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d12wuup0mza223l3lo7e.png)


Once the wax-orng send a random value back to the contract, it will mint a BabyChick:

![Hatched BabyChick](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbsmhp4wtadbittkmzyq.png)


## Conclusion

We’ve successfully implemented, deployed, and tested our NFT Smart Contract that lets users hatch their NFTs! The Smart Contract we’ve implemented in these last set of tutorials provides quite a bit of interactive functionality that you can build on to give your NFT collection its own unique properties to make it stand out.

Next post: [Deploying WAX Smart Contracts to Production](https://dev.to/idmontie/deploying-wax-smart-contracts-to-production-4649)

## E-book

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

## Additional links

- Photo by [Christin Hume](https://unsplash.com/@christinhumephoto?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/photos/Hcfwew744z4?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)