There are a couple ways to get you started.
Go to your development workspace and initialize a new project. For this tutorial, we will name the project
Norwhichand choose the
swanky phala init Norwhich
Here is a video example of the creating the new project called
swanky phala init
Norwhichdirectory and compile the
phat_helloPhat Contract that was generated with the following command:
swanky phala contract compile -c phat_hello
Here is a short clip of compiling the
swanky phala contract compile
In order to initialize a new Phat Contract project you can use our hello world template:
git clone https://github.com/Phala-Network/phat-hello
This will create a folder
phat-helloin your work directory. The folder contains a scaffold
lib.rs, which both contain the necessary building blocks for using Phat Contract.
lib.rscontains our hello world contract ‒ an ETH balance reader.
In order to build the contract just execute this command in the
cargo contract build
As a result, you’ll get the following files in the
target/inkfolder of your contract:
.contractfile combines the WASM and metadata into one file and needs to be used when instantiating the contract.
Before you really upload and deploy your contract to the blockchain, you are encouraged to run local unit tests to check its correctness.
cargo test -- --nocapture
and ensure you see all tests passed.
Do not use
cargo contract testhere,
cargo testwill give you more details if something goes wrong.
-- --nocaptureis 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.