Deploying an Agent
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.
In this section, we'll walk you through deploying a Shade Agent.
The template we're using is 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.
We'll cover 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).
On the next page, you'll see how the key components of the agent work and how to edit this agent for your specific use case.
Prerequisites
-
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.
What is a Phala Cloud
Phala Cloud is a cloud service that supports hosting applications in TEEs. It makes it easy to run an agent in TEE.
Set Up
-
First, clone the template:
git clone https://github.com/NearDeFi/shade-agent-template
cd shade-agent-template -
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
- Mac
sudo systemctl start dockerSimply open the Docker Desktop application or run:
open -a Docker -
Install dependencies:
npm i
Local Development
-
Make sure
environmentis set tolocalin thedeployment.yamlfile. -
In one terminal, run the Shade Agent CLI:
shade deployOn Linux, the CLI may prompt you to enter your sudo password.
-
Then, start your app:
npm run devYour 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 whitelistEnter the agent account ID displayed when starting the app.
TEE Deployment
-
Change the
environmenttoTEEin thedeployment.yamlfile. -
Run the Shade Agent CLI
shade deployThe 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.
Interacting with the Agent
You can interact with your agent via the APIs directly or via the frontend contained in this repo.
Direct
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
Frontend
To start the frontend, run:
cd frontend
npm i
npm run dev
To 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.
Next Steps
Now that you've successfully deployed your first Shade Agent, proceed to the key components page to understand how agents work and learn how to customize it for your specific use case.
Office Hours
Join our weekly 1-on-1, 15 minute sessions for personalized developer support and guidance for Chain Signatures and Shade Agents.
Developer Support Groups
Access async support and connect with other builders in our Telegram Communities.
Reach Out
If your team is building or considering building a production application using Chain Signatures or Shade Agents, please fill our our interest form.