WARNINGThis section is no longer recommended for deploying on Phala. To build and deploy securely and efficiently, please use the fully managed Phala Cloud platform instead. Check out the doc on how to get started.
About SideVM
SideVM is the core extension of Phat Contract. Despite the advantages above, the raw Phat Contract still has limitations compared with current Web2 backend programs:- Lifecycle limitation. The Phat Contract execution is triggered when users send on-chain transactions or off-chain queries to it, and the instance is destroyed when the execution finishes. This makes it impossible to do async requests or keep a long-live network connection;
- Program environment limitation. The Phat Contract inherits the limitations of Ink! and only supports
no_std
crates. This also limits the resources a contract can use (e.g. listening to a port for connections).
std
library, and listen to the port.
Prepare Environment
The SideVM support is already equipped to our public testnet. But it requires manual authorization to your contract to enable it to call thestart_sidevm()
function. Contact us is the #dev
channel in our Discord server to get support.
Also, you can run your local testnet following our tutorial and then do the testing.
Play with it
Programming SideVM
We use https://github.com/Phala-Network/phat-contract-examples/tree/master/start_sidevm as an example. It contains both the Phat contract and the SideVM program undersideprog
folder.
The SideVM part listens to a local port. It will be launched by this line of code if called.
Compile Phat Contract and SideVM Program
Justmake
under the folder and it will give you
- SideVM program
sideprog.wasm
- Phat contract under
target/ink/start_sidevm.contract
Upload SideVM Program and Instantiate the Contract
We have a frontend but it does not support the SideVM program upload yet. So we need to upload it manually.Upload SideVM Program
Use Polkadot.js and change the endpoint toPhala (PoC 6)
under TEST NETWORKS
.

Developer
- Extrinsics
, choose phalaFatContracts
and clusterUploadResource
. Change resourceType
to SidevmCode
, and drag your sideprog.wasm
here.
Submit the transaction and you shall see its success.
Interact with Phat UI
Go to https://phat.phala.network/, click sign in
and link your address. You need to ensure the RPC Endpoint
is wss://poc6.phala.network/ws
and Default PRuntime Endpoint
is https://phat-cluster-us.phala.network/poc6/pruntime/0xac5087e0.

Upload
and drag your target/ink/start_sidevm.contract
. Choose the default constructor and Cluster 0x0000000000000000000000000000000000000000000000000000000000000000
. Click Submit
. You should see something like

start_sidevm
query is used to start the SideVM program. It contains the invoke to pink::start_sidevm()
.
From the Worker log, we can see

More Resources
We do not have many documents on SideVM yet, feel free to ask us directly.- Previous SideVM design: https://github.com/Phala-Network/rfcs/blob/main/pink-sidevm/pink-sidevm.md
- SideVM program examples under https://github.com/Phala-Network/phala-blockchain/tree/master/crates/pink/sidevm/examples
- Our SideVM-related PRs: https://github.com/Phala-Network/phala-blockchain/pulls?q=sidevm+