Skip to main content

Quick Start: Hello World Contract

Prerequisites

Steps

1. Clone the Contract Repository

Start by cloning the existing GitHub repository containing the Hello World contract to your local environment:

git clone https://github.com/Wire-Network/guides.git && cd guides/hello-world-contract

Then open the code into your favorite code editor and inspect the files.

2. Compile the Contract

Compile it using the ./build.sh. This script uses the Wire Contract Development Toolkit (CDT) the Hello World contract into WebAssembly (WASM) format. The script will create a compilation folder hello/ with the WASM and ABI files.

./build.sh

Upon successful compilation, you will see a hello folder with hello.abi and hello.wasm files.

hello-world-contract/
|   ....
├── hello
│ ├── hello.abi
│ └── hello.wasm
| ...

3. Deploy the Contract

Before deploying, ensure you have an account to deploy the contract to. Create an account if necessary and replace YOUR_PUBLIC_KEY with your actual public key when you created a wallet(see Import Keys). Your wallet must be also unlocked before using it(see Unlock a wallet)

3.1. Create an account using clio

clio create account sysio hello $PUBLIC_KEY -p sysio@active

This command enables the sysio system account to create a new account named hello on the Wire blockchain. The -p sysio@active specifies that the active permission of the sysio account is used to authorize the account creation.

3.2. Deploy the contract

./deploy.sh

4. Push a Transaction

Invoke the hi action within the contract:

clio push action hello hi '["bob"]' -p bob@active

This command triggers the hi action for the user bob, and if authorized by bob, it prints "Hello, bob".

bob-says-hi

Repeat the same passing "alice" as data to the action and using the same permissions:

clio push action hello hi '["alice"]' -p bob@active

bob-invoke-with-alice

5. Change the contract code

Next, let's change the contract code by enabling require_auth() function and see firsthand how checks and permissions work in contract actions. If there's a mismatch between the authorizing user and the user parameter, the contract will not execute due to the require_auth check.

Comment out Line 5 in hello.cpp

hello.cpp
#include <hello.hpp>


void hello::hi(name user) {
require_auth(user);
print("Hello, ", user);
}

Recompile and redeploy the contract. Then execute:

clio push action hello hi '["alice"]' -p bob@active

This will result in an authorization error since bob is trying to execute an action that requires alice's permission.

CLI output:

missing-authority


Bonus ⭐️

Inspect the contract on Wire Hub Block Explorer

Feel free to explore your contract on Wire Hub Block Explorer. Use this guide to connect to your chain and inspect the contract.