Create Contract

Create and Compile Your First Contract

There are a couple ways to get you started.

If you have not installed swanky phala CLI tool, follow these steps to get started.

Go to your development workspace and initialize a new project. For this tutorial, we will name the project Norwhich and choose the phat_hello template.

swanky phala init Norwhich

Here is a video example of the creating the new project called Norwhich.

Next, cd into the Norwhich directory and compile the phat_hello Phat Contract that was generated with the following command:

swanky phala contract compile -c phat_hello

Here is a short clip of compiling the phat_hello contract.

As a result, you’ll get the following files in the target/ink folder of your contract: phat_hello.wasm, metadata.json, and phat_hello.contract. The .contract file combines the WASM and metadata into one file and needs to be used when instantiating the contract.

Run Unit Tests Locally

Before you really upload and deploy your contract to the blockchain, you are encouraged to run local unit tests to check its correctness.

In the phat-hello folder, run

cargo test -- --nocapture

and ensure you see all tests passed.

Do not use cargo contract test here, cargo test will give you more details if something goes wrong.

-- --nocapture is optional to see the output during testing.

Now you have successfully compiled and locally test your first Phat Contract. Now it’s time to deploy it to a real blockchain.

Last updated

Logo

COPYRIGHT Β© 2024 PHALA.LTD ALL RIGHTS RESERVED. May Phala be with you!