Skip to main content

Compile a Smart Contract via CLI

Overview

This guide provides instructions for compiling a smart contract using the command line interface (CLI).

Prerequisites

info

This contract is a slightly longer version of Quick Start: Hello World Contract.

Steps

Complete the following steps to compile a smart contract using the CLI:

1. Navigate to the Contract Directory

Navigate to the hello folder in examples (./examples/hello). You should see the ./src/hello.cpp file.

2. Create Build Directory

Create a build directory and navigate to it:

mkdir build
cd build

3. Compile the Contract

Run the following command to compile the contract:

cdt-cpp ../src/hello.cpp -o hello.wasm -I ../include/

This command compiles the input CPP source file (../src/hello.cpp) and generates a WASM file named hello.wasm. The -I ../include/ flag specifies the include folder path for header files.

4. Verify Generated Files

After successful compilation, verify that the following two files were generated:

  • Compiled binary WASM: hello.wasm
  • Generated ABI file: hello.abi

Reference

Relevant tools and methods:

Next Steps