DEV Community

Cover image for Deploying the WAX Guestbook Contract Locally
Ivan Montiel
Ivan Montiel

Posted on • Updated on

Deploying the WAX Guestbook Contract Locally

Introduction

In the last section, we covered writing a WAX Guestbook Contract where accounts will be able to sign the contract with a memo that will be stored on the blockchain. In this section, we will deploy this contract to our locally running blockchain to test it out.

Deploying the Contract Locally

Let’s deploy out contract to a blockchain in order to test it. Since this is a simple, self-contained contract, we can deploy to locally to test it before even interacting with a testnet blockchain. This is extremely useful when you want to test your contracts, but not worry about dealing with WAXP and RAM costs.

In the previous sections of the tutorial, when we started our Docker instance, we also started nodeos. We will need nodeos running in order to deploy locally.

Let’s deploy the Smart Contract:

cleos set contract guestbook123 ./guestbook/build/guestbook -p guestbook123@active
Enter fullscreen mode Exit fullscreen mode

Here we’ve called the cleos set contract action on our CLI, with the following arguments:

  • guestbook123 - the smart contract’s account
  • ./guestbook/build/guestbook - the path that contains our contract’s wasm file
  • -p guestbook123@active the active permission for our smart contract’s account

Example output:

Success output

We have successfully deployed the contract to our locally running WAX blockchain node! Our node isn’t connected to any other nodes, so no one else will be able to access our Smart Contract, but we can still interact with it to make sure it works.

Interacting with the Contract

Now that we have deployed our contract to our local environment, its time to test some of the functionality!

We will start by signing the guestbook:

cleos push action guestbook123 sign '["guestbook123","hello there"]' -p guestbook123@active
Enter fullscreen mode Exit fullscreen mode

This time, we are pushing an action to the blockchain using the cleos push action CLI command with the following arguments:

  • guestbook123 - the smart contract’s account
  • '["guestbook123","hello there"]' - the payload that matches the ACTION signature we want to call.
  • -p guestbook123@active the active permission for our smart contract’s account

Example output:

executed transaction: 7933cbb485e2a329d0d98c60c61ceffd1b0d7a4f33f87456b5518dddfcf6657e  112 bytes  357 us
#  guestbook123 <= guestbook123::sign           {"nm":"guestbook123","memo":"hello there"}
warning: transaction executed locally, but may not be confirmed by the network yet         ]
Enter fullscreen mode Exit fullscreen mode

Let’s view the table’s contents to see how it looks:

cleos get table guestbook123 guestbook123 guestbook
Enter fullscreen mode Exit fullscreen mode
  • guestbook123 is the contract account
  • The second guestbook123 is the “scope” of the table we are searching, this was set when we created the table in our contract
  • guestbook is the name of the table we specified in our contract.

Here I tested calling the contract multiple times, each time a new entry is added to the table:

Example table output

Thinking Big

While this contract only stores an account name and a memo, you can imagine how powerful this is for creating interactive experiences on the blockchain. In Dark Emblem NFT, we use blockchain tables to store our on-chain currency, store which cards are staked to the contract, and we use them to power our Raids where gamers can group up to tackle bosses with their NFTs.

Tables and Actions are the cornerstone of amazing interactive blockchain experiences, so think big!

Conclusion

In this section, we were able to deploy our Guestbook Smart Contract from the last section to our locally running blockchain, sign it, and then view the data.

In upcoming parts of this tutorial series, we are going to deploy that contract to the Testnet and interact with it via more common tools like Bloks.io.

Next post: Deploying the WAX Guestbook Contract to the Testnet

E-book

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

Additional links

Top comments (0)