This is a template for developing a Node.js (Typescript) w/ Express app with boilerplate code targeting deployment on Phala Cloud and DStack. It includes the SDK by default to make integration with TEE features easier. This repo also includes a default Dockerfile and docker-compose.yml for deployment.
First, follow these steps to set up your development environment.
Install the Phala CLI globally:
npm i -g phala
phala helpClone the repository:
git clone --depth 1 https://github.com/Gldywn/phala-cloud-node-starter.git
cd phala-cloud-node-starterInstall dependencies and create your .env file from the template:
npm i
cp env.example .envBefore running the development server, you need to have an active DStack simulator running.
Start the simulator:
phala simulator start
# You will get something like this
✓ Setting environment for current process...
✓ DSTACK_SIMULATOR_ENDPOINT=/<user>/.phala-cloud/simulator/0.5.3/dstack.sock
✓ TAPPD_SIMULATOR_ENDPOINT=/<user>/.phala-cloud/simulator/0.5.3/tappd.sock
✓ TEE simulator started successfullyDSTACK_SIMULATOR_ENDPOINT variable inside your .env file with the one output by the start command.
Once the simulator is running, you can start your Express development server:
npm run devBy default, the Express development server will listen on port 3000. Open http://localhost:3000/get_quote in your browser to get a quote with Hello DStack! as report data.
This repo also includes code snippets for the following common use cases:
/: Returns the TCB Info of the hosted CVM./get_quote: ThereportdataisHello DStack!and generates a quote for an attestation report via thegetQuoteAPI. You can see the raw textHello DStack!by pasting yourquoteinto the Attestation Explorer./get_key: Basic example of thegetKeyAPI./ethereum: Using thegetKeyAPI to generate a deterministic wallet for Ethereum, a.k.a. a wallet held by the TEE instance./solana: Using thegetKeyAPI to generate a deterministic wallet for Solana, a.k.a. a wallet held by the TEE instance.
The provided docker-compose.yml includes a shared logging config to restrict log growth as recommended here.
Build a linux/amd64 image locally via Docker:
phala docker build --image phala-cloud-node-starter --tag latestThe workflow .github/workflows/phala-docker-build.yml validates the Docker build. It is optional and serves as a helper if you need automated checks. On each PR and push to main, it performs a Docker build using phala docker build.
Log in to Docker using Phala CLI:
phala docker loginPush your linux/amd64 image to Docker Hub:
phala docker push --image <docker-user>/phala-cloud-node-starter:latestDeploy a new CVM instance using your Docker Compose file:
phala deploy docker-compose.yml
# You will get something like this
CVM created successfully!
CVM ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Name: phala-cloud-node-starter # (truncated to 20 chars)
App ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Dashboard URL: https://cloud.phala.network/dashboard/cvms/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
This repository covers the basics of creating a DStack-powered application and deploying it to Phala Cloud. For more detailed information, please refer to the resources below.
This starter requires DStack v0.5 or higher for deployment on Phala Cloud, which is currently running a closed beta for this version. If your deployed CVM is not yet on v0.5, please request beta access on the official Telegram or Discord.