
Developing production-grade applications within a mono repository can be a daunting task, especially without proper package management. As a developer focused on agility and innovation, you need a build system, that not only matches your pace but also ensures stability.
Monorepositories are gaining substantial traction in the world of project management, especially within large enterprises. This methodology, originally pioneered by Google, is now widely adopted due to its exceptional ability to facilitate package sharing, promote code reusability, foster collaboration, and streamline the bug-fixing process.
In this article, we will introduce you to a powerful build system called Turbo Repo. Developed by the Vercel team, Turbo Repo is designed to enhance the developer experience. It boasts an incremental bundler optimized for JavaScript and TypeScript, and it's written in Rust. We'll explore how you can leverage this monorepository setup to create robust, internet-aware DApps for the Phala Network.
Let's dive right in and set up your Phala Turbo Repo environment. Follow these steps to get started:
Create a new Phala Turbo Starter from this GitHub repository using the following commands:
npx degit markkos89/turbo-monorepo-template my-monorepo
cd my-monorepo
pnpm install
This will initialize a new project called my-monorepo for you, with a folder structure similar to the one below:
📦 root
┣ 📂 .github
┣ 📂 .husky
┣ 📂 .vscode
┣ 📂 apps
┃ ┣ 📂 lens-api-code-examples
┃ ┣ 📂 lens-oracle
┃ ┣ 📂 website-ssr
┃ ┗ 📂 website
┣ 📂 packages
┃ ┣ 📂 eslint-config-custom
┃ ┣ 📂 jest-config
┃ ┣ 📂 lighthouse-config
┃ ┣ 📂 next-config
┃ ┣ 📂 playwright-config
┃ ┣ 📂 storybook-config
┃ ┣ 📂 tailwindcss-config
┃ ┣ 📂 typescript-config
┃ ┣ 📂 ui
┃ ┗ 📂 utils
┣ 📜 package.json
┗ 📜 turbo.json
In the apps directory, you'll find templates to kickstart your projects, including lens-api oracle templates, server-side rendered website templates, and lens oracle templates.
If you wish to develop with Next.js and want to start apps/website-ssr and apps/website in development mode while watching for changes in packages/ui, run the following command at the root:
To build apps/website-ssr and apps/website for production, execute the following command at the root:
If you want to analyze the generated bundles, specify the ANALYZE environment variable:
ANALYZE=true pnpm build
To preview production builds of apps/website-ssr and apps/website, run the following command at the root:
pnpm start
For developing with Storybook, if you wish to build all Storybook projects, execute this command at the root:
# run in development mode
pnpm storybook:dev
# build for production
pnpm storybook:build
To run unit/e2e tests for all projects, use this command at the root:
# to run unit tests
pnpm test:unit
# to run e2e tests
pnpm test:e2e
For linting across all projects, run the following command at the root:
The Phala Turbo Repo is designed to foster collaboration among developers. It provides a shared workspace where developers can work together on projects, review each other’s code, and contribute to the development of applications that leverage Phala Network decentralized computing. This collaborative environment not only speeds up the development process but also ensures the production of high-quality, robust applications.
One of the key features of the Phala Turbo Repo is its streamlined bug-fixing process. Developers can easily track, report, and fix bugs in their applications. The repo provides tools for bug tracking and version control, making it easier for developers to identify and resolve issues. This leads to more stable and reliable applications.
The Phala Turbo Repo promotes code reusability and package sharing. Developers can share their code packages with others, allowing them to reuse code snippets and avoid reinventing the wheel. This not only saves time but also leads to more consistent and efficient code.
Now that you've familiarized yourself with Phala Turbo Repo and set up your development environment, let's delve into leveraging this powerful tool for Phala Network development. Building applications that utilize Phat contracts and interact with the Phala Network's off-chain Workers can open up a world of possibilities. Here's how you can take advantage of the Phala Turbo Repo for your Phala development journey:
Phat contracts serve as a bridge between off-chain and on-chain worlds within the Phala Network ecosystem. These contracts run on Phala Network's off-chain Workers and enable various capabilities, including internet connectivity, off-chain computation, and verifiable computation for smart contracts.
To work with Phala Network and Phat contracts, you need a Polkadot account. Follow these steps to create your Bricks Profile account on the Phala PoC5 Testnet or Phala Mainnet:
Visit the Phala PoC5 Testnet or Phala Mainnet.
Create your Bricks Profile account by following the provided instructions. You may refer to this YouTube video on setting up your account from scratch.
Once your Bricks Profile account is created, you will have access to an overview of your account information.
The Phala monorepository comes prepacked with all you need to work with Phala already set up and can help you deploy your contract at a go. Let's see how we can deploy a simple function. First cd into apps/lens-oracle.
Step 1: Install dependencies and compile contract
# install dependencies
$ pnpm install --filter lens-oracle
Step 2: Build your phala function
# build phala function
pnpm build-function
Step 3: Running local tests
# test your function locally
pnpm hardhat test
Step 4: Compile the consumer contract
# run compile
pnpm compile
Step 5: Deploy the consumer contract on localhost
# Run a hardhat node
pnpm hardhat node
# deploy to local node
pnpm localhost-deploy
Step 6: Test your function locally
# start watching your node
pnpm localhost-watch <deployed_contract_address> artifacts/contracts/TestLensApiConsumerContract.sol/TestLensApiConsumerContract.json dist/index.js -a https://api-mumbai.lens.dev/
# run a test push message
LOCALHOST_CONSUMER_CONTRACT_ADDRESS=<deployed_contract_address> pnpm localhost-push-request
Congrats, you have just accessed the internet from a smart contract. You can learn more about Phala network by going to their docs. You can also take a look at this example to get started.

Developing production-grade applications within a mono repository can be a daunting task, especially without proper package management. As a developer focused on agility and innovation, you need a build system, that not only matches your pace but also ensures stability.
Monorepositories are gaining substantial traction in the world of project management, especially within large enterprises. This methodology, originally pioneered by Google, is now widely adopted due to its exceptional ability to facilitate package sharing, promote code reusability, foster collaboration, and streamline the bug-fixing process.
In this article, we will introduce you to a powerful build system called Turbo Repo. Developed by the Vercel team, Turbo Repo is designed to enhance the developer experience. It boasts an incremental bundler optimized for JavaScript and TypeScript, and it's written in Rust. We'll explore how you can leverage this monorepository setup to create robust, internet-aware DApps for the Phala Network.
Let's dive right in and set up your Phala Turbo Repo environment. Follow these steps to get started:
Create a new Phala Turbo Starter from this GitHub repository using the following commands:
npx degit markkos89/turbo-monorepo-template my-monorepo
cd my-monorepo
pnpm install
This will initialize a new project called my-monorepo for you, with a folder structure similar to the one below:
📦 root
┣ 📂 .github
┣ 📂 .husky
┣ 📂 .vscode
┣ 📂 apps
┃ ┣ 📂 lens-api-code-examples
┃ ┣ 📂 lens-oracle
┃ ┣ 📂 website-ssr
┃ ┗ 📂 website
┣ 📂 packages
┃ ┣ 📂 eslint-config-custom
┃ ┣ 📂 jest-config
┃ ┣ 📂 lighthouse-config
┃ ┣ 📂 next-config
┃ ┣ 📂 playwright-config
┃ ┣ 📂 storybook-config
┃ ┣ 📂 tailwindcss-config
┃ ┣ 📂 typescript-config
┃ ┣ 📂 ui
┃ ┗ 📂 utils
┣ 📜 package.json
┗ 📜 turbo.json
In the apps directory, you'll find templates to kickstart your projects, including lens-api oracle templates, server-side rendered website templates, and lens oracle templates.
If you wish to develop with Next.js and want to start apps/website-ssr and apps/website in development mode while watching for changes in packages/ui, run the following command at the root:
To build apps/website-ssr and apps/website for production, execute the following command at the root:
If you want to analyze the generated bundles, specify the ANALYZE environment variable:
ANALYZE=true pnpm build
To preview production builds of apps/website-ssr and apps/website, run the following command at the root:
pnpm start
For developing with Storybook, if you wish to build all Storybook projects, execute this command at the root:
# run in development mode
pnpm storybook:dev
# build for production
pnpm storybook:build
To run unit/e2e tests for all projects, use this command at the root:
# to run unit tests
pnpm test:unit
# to run e2e tests
pnpm test:e2e
For linting across all projects, run the following command at the root:
The Phala Turbo Repo is designed to foster collaboration among developers. It provides a shared workspace where developers can work together on projects, review each other’s code, and contribute to the development of applications that leverage Phala Network decentralized computing. This collaborative environment not only speeds up the development process but also ensures the production of high-quality, robust applications.
One of the key features of the Phala Turbo Repo is its streamlined bug-fixing process. Developers can easily track, report, and fix bugs in their applications. The repo provides tools for bug tracking and version control, making it easier for developers to identify and resolve issues. This leads to more stable and reliable applications.
The Phala Turbo Repo promotes code reusability and package sharing. Developers can share their code packages with others, allowing them to reuse code snippets and avoid reinventing the wheel. This not only saves time but also leads to more consistent and efficient code.
Now that you've familiarized yourself with Phala Turbo Repo and set up your development environment, let's delve into leveraging this powerful tool for Phala Network development. Building applications that utilize Phat contracts and interact with the Phala Network's off-chain Workers can open up a world of possibilities. Here's how you can take advantage of the Phala Turbo Repo for your Phala development journey:
Phat contracts serve as a bridge between off-chain and on-chain worlds within the Phala Network ecosystem. These contracts run on Phala Network's off-chain Workers and enable various capabilities, including internet connectivity, off-chain computation, and verifiable computation for smart contracts.
To work with Phala Network and Phat contracts, you need a Polkadot account. Follow these steps to create your Bricks Profile account on the Phala PoC5 Testnet or Phala Mainnet:
Visit the Phala PoC5 Testnet or Phala Mainnet.
Create your Bricks Profile account by following the provided instructions. You may refer to this YouTube video on setting up your account from scratch.
Once your Bricks Profile account is created, you will have access to an overview of your account information.
The Phala monorepository comes prepacked with all you need to work with Phala already set up and can help you deploy your contract at a go. Let's see how we can deploy a simple function. First cd into apps/lens-oracle.
Step 1: Install dependencies and compile contract
# install dependencies
$ pnpm install --filter lens-oracle
Step 2: Build your phala function
# build phala function
pnpm build-function
Step 3: Running local tests
# test your function locally
pnpm hardhat test
Step 4: Compile the consumer contract
# run compile
pnpm compile
Step 5: Deploy the consumer contract on localhost
# Run a hardhat node
pnpm hardhat node
# deploy to local node
pnpm localhost-deploy
Step 6: Test your function locally
# start watching your node
pnpm localhost-watch <deployed_contract_address> artifacts/contracts/TestLensApiConsumerContract.sol/TestLensApiConsumerContract.json dist/index.js -a https://api-mumbai.lens.dev/
# run a test push message
LOCALHOST_CONSUMER_CONTRACT_ADDRESS=<deployed_contract_address> pnpm localhost-push-request
Congrats, you have just accessed the internet from a smart contract. You can learn more about Phala network by going to their docs. You can also take a look at this example to get started.

Verifying OTP On-Chain with Phala Phat Functions
The blockchain is immutable and not internet-aware, as everything must be provable and guaranteed to remain the same. This makes asynchronous operations impossible. Blockchain oracles and off-chain data are critical in the blockchain ecosystem because they enable smart contracts to interact with the real world and utilize datasets such as weather forecasting, financial trading, bots, and messaging services. This bridges the gap between Web2 and Web3, paving the way for mass adoption. Securing...

Interoperable Lending with Zero Knowledge Proofs
There has been a growing interest in using zero-knowledge proofs in the financial industry in recent years. These cryptographic primitives allow one party to prove the validity of a statement to another party without revealing any additional information. This can potentially revolutionize how we think about privacy and security concerning blockchain transactions.One area where zero-knowledge proofs could have a significant impact is in lending protocols. By leveraging off-chain data, identity...

Verifying OTP On-Chain with Phala Phat Functions
The blockchain is immutable and not internet-aware, as everything must be provable and guaranteed to remain the same. This makes asynchronous operations impossible. Blockchain oracles and off-chain data are critical in the blockchain ecosystem because they enable smart contracts to interact with the real world and utilize datasets such as weather forecasting, financial trading, bots, and messaging services. This bridges the gap between Web2 and Web3, paving the way for mass adoption. Securing...

Interoperable Lending with Zero Knowledge Proofs
There has been a growing interest in using zero-knowledge proofs in the financial industry in recent years. These cryptographic primitives allow one party to prove the validity of a statement to another party without revealing any additional information. This can potentially revolutionize how we think about privacy and security concerning blockchain transactions.One area where zero-knowledge proofs could have a significant impact is in lending protocols. By leveraging off-chain data, identity...
multi-disciplinary coder
multi-disciplinary coder
Share Dialog
Share Dialog

Subscribe to peter 🧩

Subscribe to peter 🧩
<100 subscribers
<100 subscribers
No activity yet