Warning
The Shade Agent Framework has not yet undergone a formal audit.
No representations or warranties are made regarding security, correctness, or fitness for any purpose. Use of this software is entirely at your own risk.
This repo contains a simple Shade Agent built with Hono and written in TypeScript that acts as a verifiable ETH price oracle. It fetches the price of Eth from two different APIs, takes the average, and then pushes the price to an Ethereum contract.
You can try the live demo here and view the full documentation here.
There are two deployment scenarios:
- Local Development: Running the agent locally for rapid testing and development.
- TEE Deployment: Running the agent in a real Trusted Execution Environment (TEE).
-
Install the Shade Agent CLI:
npm i -g @neardefi/shade-agent-cli
-
Set up Docker if you have not already:
-
Set up a free Phala Cloud account at https://cloud.phala.network/register, then get an API key from https://cloud.phala.network/dashboard/tokens.
Phala Cloud is a cloud service that supports hosting applications in TEEs. It makes it easy to run an agent in TEE.
-
First set up NEAR and Phala credentials in the CLI:
shade auth set all testnet create-new -
Set a unique
agent_contract.contract_id(e.g. example-contract-123.testnet) and fill in yourbuild_docker_image.tag(e.g. pivortex/my-first-agent) in thedeployment.yamlfile. -
Create a
.envfile and configure your environment variables.
AGENT_CONTRACT_ID= Set this to the agent contract ID you set in the deployment.yaml file
SPONSOR_ACCOUNT_ID= Set this to the NEAR account ID generated by the CLI
SPONSOR_PRIVATE_KEY= Set this to the private key generated by the CLI-
Start up Docker:
Linux:
sudo systemctl start docker
Mac:
Simply open the Docker Desktop application or run:
open -a Docker
-
Install dependencies:
npm i
-
Make sure
environmentis set tolocalin thedeployment.yamlfile. -
In one terminal, run the Shade Agent CLI:
shade deploy
On Linux, the CLI may prompt you to enter your sudo password.
-
Then, start your app:
npm run dev
Your app will start on http://localhost:3000
-
Lastly, you need to whitelist the agent in the agent contract (only needed for local development). In another terminal, run:
shade whitelist
Enter the agent account ID displayed when starting the app.
-
Change the
environmenttoTEEin thedeployment.yamlfile. -
Run the Shade Agent CLI
shade deploy
The CLI on Linux may prompt you to enter your sudo password.
The CLI will output the URL of your app.
After deploying to Phala Cloud, monitor your deployments and delete unused ones to avoid unnecessary costs. You can manage your deployments from thedashboard.
You can interact with your agent via the APIs directly or via the frontend contained in this repo.
For Phala deployments, swap localhost:3000 for your deployment URL.
-
Get information about the agent:
http://localhost:3000/api/agent-info -
Get the derived Ethereum Sepolia price pusher account ID and its balance (you will need to fund this account):
http://localhost:3000/api/eth-info -
Request the agent to update the price of Eth:
http://localhost:3000/api/transaction
To start the frontend, run:
cd frontend
npm i
npm run devTo use the frontend with your Phala deployment, change the API_URL to the Phala URL in your config.js file.
In the frontend, you can review the approved measurements and PPID in the contract and details of the registered agents.