Deploying an Agent
In this section, we'll walk you through deploying a Shade Agent. The Shade Agent Framework abstracts the complexities of creating a agent by removing TEE specific code and handling the deployment of the agent contract under hood.
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 to edit this agent for your specific use case.
Prerequisites
-
First,
clone
the template.git clone https://github.com/NearDeFi/shade-agent-template
cd shade-agent-template -
Install NEAR and Shade Agent tooling:
# Install the NEAR CLI
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh
# Install the Shade Agent CLI
npm i -g @neardefi/shade-agent-cli -
Create a
NEAR testnet account
and record the account name andseed phrase
:near account create-account sponsor-by-faucet-service example-name.testnet autogenerate-new-keypair print-to-terminal network-config testnet create
replacing
example-name.testnet
with a unique account Id. -
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 service that offers secure and private hosting in a TEE using Dstack. Phala Cloud makes it easy to run a TEE, that's why we use it in our template!
Set up
-
Rename the
.env.development.local.example
file name to.env.development.local
and configure your environment variables. -
Start up Docker:
- Linux
- Mac
sudo systemctl start docker
Simply open the Docker Desktop application or run:
open -a Docker
-
Install dependencies
npm i
This technology has not yet undergone a formal audit. Please conduct your own due diligence and exercise caution before integrating or relying on it in production environments.
Local Development
-
Make sure the
NEXT_PUBLIC_contractId
prefix is set toac.proxy.
followed by your NEAR accountId. -
In one terminal, run the Shade Agent CLI:
shade-agent-cli
The CLI on Linux may prompt you to enter your
sudo password
. -
In another terminal, start your app:
npm run dev
Your app will start on https://localhost:3000
TEE Deployment
-
Change the
NEXT_PUBLIC_contractId
prefix toac.sandbox.
followed by your NEAR accountId. -
Run the Shade Agent CLI
shade-agent-cli
The CLI on Linux may prompt you to enter your
sudo password
.The last
URL
the CLI outputs is the URL of your app. If your application is not working, head over to your App on the Phala Dashboard and review the logs.
Interacting with the Agent
You can interact with your agent via the APIs directly or via a lightweight frontend contained in this repo.
Direct
For Phala deployments, swap localhost:3000 for your deployment URL.
-
Get the Agent account Id and its balance:
https://localhost:3000/api/agent-account
-
Get the derived Ethereum Sepolia price pusher account Id and its balance (you will need to fund this account):
https://localhost:3000/api/eth-account
-
Send a transaction through the agent to update the price of Eth:
https://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 Phala URL in your config.js file.
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.