Try the live demo
See the ETH price oracle agent in action
- Local Development: Running the agent locally for rapid testing and development.
- TEE Deployment: Running the agent in a real Trusted Execution Environment (TEE).
Prerequisites
Create a NEAR testnet account
Create a NEAR testnet account and record the account name and seed phrase:Replace
example-name.testnet with a unique account ID.Create a Phala Cloud account
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 Phala Cloud?
What is Phala Cloud?
Phala Cloud is a cloud service that supports hosting applications in a TEE. It makes it easy to run an agent in TEE.
Setup
Configure environment variables
Rename the
.env.development.local.example file to .env.development.local and configure your environment variables.Local development
Configure contract ID
Make sure the
NEXT_PUBLIC_contractId prefix is set to ac-proxy. followed by your NEAR accountId.Run the Shade Agent CLI
In one terminal, run:The CLI on Linux may prompt you to enter your
sudo password.Start your app
TEE deployment
Configure contract ID
Change the
NEXT_PUBLIC_contractId prefix to ac-sandbox. followed by your NEAR accountId.Run the Shade Agent CLI
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.After deploying to Phala Cloud, monitor your deployments and delete unused ones to avoid unnecessary costs. You can manage your deployments from the dashboard.Interacting with the agent
You can interact with your agent via the APIs directly or via a lightweight frontend contained in this repo.- Direct API
- Frontend
Understanding the template
The template is a simple Shade Agent that acts as a verifiable ETH price oracle. The project has three different APIs:1. Agent account
This API fetches the agent’s NEAR account ID and its balance by using theagentAccountId and agent("getBalance") functions from the shade-agent-js library.
2. ETH account
This API returns theEthereum Sepolia account that the Shade Agent uses to update the price of Ethereum in the Sepolia contract. This API is used so the user knows which account to fund for gas.
3. Transaction
This is where the core logic of the agent is defined. When this API is called, the agent will build and sign a transaction.Signing transactions
In the transaction API route, therequestSignature function from the shade-agent-js library is used to sign a transaction.
First, the agent retrieves the price of ETH by querying two different APIs and calculating the average.
Next, the agent builds the transaction payload to be signed using the chainsig.js library:
- Derive the Ethereum address that will be sending the transaction. This function takes the agent contract account ID and a path. The path can be any string you like - different paths will derive different addresses.
- Create the data. This is what action we’re performing, in this case, a function call to update the price in the contract.
- Build the transaction and the transaction payload by inputting the derived address, the target Ethereum smart contract, and the data.
requestSignature function to sign the transaction. We specify the keyType as Ecdsa as we’re signing for a blockchain that uses the secp256k1 signature scheme.
The result is the signature.
We then attach the signature to the Ethereum transaction and broadcast it to the target network.
Using different chains
The template sets up a chain adapter for Ethereum Sepolia using thechainsig.js library. This library allows you to easily construct transaction payloads to be signed by the agent.
You can set up chain adapters for a variety of chains, including EVM, Bitcoin, NEAR, Solana, SUI, XRP, Cosmos, and more to allow your agent to interact with multiple different chains. You can see a full list of the chains currently supported here.
If you are using a chain that uses the ed25519 signature scheme (NEAR, Solana, SUI, Aptos, etc.), you should specify the keyType as Eddsa when calling requestSignature.
Next steps
Framework Overview
Dive deeper into the framework to understand the core concepts needed for building production-ready Shade Agents.