Deploying the WAX Guestbook Contract to the Testnet
Ivan Montiel
Posted on July 30, 2023
Introduction
In the previous section, we deployed our Guestbook contract to our local WAX node. This is useful for testing self-contained contracts, but as we start working on more complex WAX Smart Contracts that interact with other contracts, we will need to use the WAX testnet.
In this section, we will deploy and interact with our WAX Smart Contract to the WAX testnet using similar CLI commands as before.
Unlock your wallet
If you have been working through these tutorials, you may have noticed that a CLI command may fail, telling you that the wallet you are trying to use is locked. Cleos will automatically close wallets after some time of inactivity, but you can unlock your wallet again with:
cleos wallet open -n testwallet
cleos wallet unlock -n testwallet --password="$(cat ./secrets)"
Deploying to the Testnet
Similarly to the previous commands in the last section, we can deplot to the testnet using cleos
. We will need to use our testnet account name from before, which is waxcourse123
for me. This may be different from the local account name you set up, which was guestbook123
in our previous examples.
cleos -v -u https://testnet.wax.pink.gg set contract waxcourse123 ./guestbook/build/guestbook -p waxcourse123@active
If you notice, this is the same as the local deployment, just with an extra flag for setting the url to send the command to. I also like setting the -v
flag to make sure to be verbose to debug any errors.
This command may give you an error:
Reading WASM from /wax/guestbook/build/guestbook/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:
# 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
The benefit of deploying to a testnet is we also get access to all of the tooling that has been built around the testnet. These are the same tools we will use when we deploy to the production blockchain as well.
Interacting with your Smart Contract via CLI
Just like before, we can interact with our contract, but against the deployed Testnet version instead of our local version of the blockchain:
# Remember to change waxcourse123 to your account name
cleos -v -u https://testnet.wax.pink.gg \
push action waxcourse123 sign '["waxcourse123","hello there"]' \
-p waxcourse123@active
And now let’s get the current state of the table from the testnet:
cleos -v -u https://testnet.wax.pink.gg \
get table waxcourse123 waxcourse123 guestbook
Example response:
Using Bloks.io
But interacting with the contract via just a CLI can be tiresome - especially trying to remember all of the commands and flags.
Instead, let’s use Bloks: https://wax-test.bloks.io/. You can use Bloks to view WAX transactions via a web interface and interact with contracts.
For example, here is the account I have been using, up to this point in the tutorial: https://wax-test.bloks.io/account/waxcourse123.
If we navigate to the “Contract” tab, and then the “Actions” sub-tab, we can interact with our contract that we have deployed to our WAX account.
You can click “sign”, which is the action we created in our C++ smart contract, then we can fill in the data to send to the contract and click Submit Transaction:
You will need to sign the transaction using a 3rd party tool, like Anchor.
Thinking Securely
It’s important to continuously test that your Smart Contracts are working as expected, especially from a security point of view. It can be useful to deploy a Smart Contract and create multiple accounts – some with authority to run certain Actions within your contract, and some without. Then you can test that Actions properly fail when a non-authorized account attempts an Action.
At Dark Emblem NFT, nearly every change goes to the Testnet first in order to validate that the contract works as expected.
Conclusion
Congratulations, we’ve created our first Smart Contract, tested it locally, and even deployed it to a testnet!
Up next, we’ll start diving into NFTs by creating a simple NFT Smart Contract.
Next post: A Simple WAX NFT
E-book
Get this entire WAX tutorial as an e-book on Amazon.
Additional links
- Github: https://github.com/CapsuleCat/wax-nft-tutorial/tree/main/guestbook
- waxcourse123 on Bloks.io: https://wax-test.bloks.io/account/waxcourse123
- Further reading, Smart Contract Security for Developers: https://scsfg.io/developers/. This site focuses on ETH Solidity contracts, but the principles still apply.
- Photo by Sigmund on Unsplash
Posted on July 30, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.