Build An Agent to Transact Onchain
Last updated
Was this helpful?
Last updated
Was this helpful?
WARNING
This section is no longer recommended for deploying on Phala. To build and deploy securely and efficiently, please use the fully managed platform instead. Check out the doc on how to .
If you like video tutorials, here is one of our latest workshops on building an Agent to transact onchain using the with the AI Agent Contract Template. In this tutorial, you will learn:
How to test the WapoJS functions like deriveSecret(salt)
to derive an ECDSA key based on your secret
added to your Agent Contract's secret vault.
Build and deploy your Agent Contract to IPFS then add your secret salt that will derive an ECDSA key for your deployed agent.
Sign and verify a message using the viem
SDK with your agent's derived ECDSA key.
Debug your Agent Contract due to a failed transaction on Base Sepolia.
Resolve the error and execute a successful transaction on Base Sepolia.
Install dependencies
Create .env
file with the default ThirdWeb API key for publishing your Agent Contract to IPFS
Build your Agent
Test your Agent locally
Expected Test Results
Upload your compiled AI Agent code to IPFS.
Upon a successful upload, the command should show the URL to access your AI Agent.
Did Thirdweb fail to publish?
Once published, your AI Agent is available at the URL: https://wapo-testnet.phala.network/ipfs/<your-cid>
. You can get it from the "Publish to IPFS" step.
You can test it with curl
.
By default, all the compiled JS code is visible for anyone to view if they look at IPFS CID. This makes private info like API keys, signer keys, etc. vulnerable to be stolen. To protect devs from leaking keys, we have added a field called secret
in the Request
object. It allows you to store secrets in a vault for your AI Agent to access.
To add your secrets,
Run command to set the secrets
Expected output:
The API returns a token
and a key
. The key
is the id of your secret. It can be used to specify which secret you are going to pass to your frame. The token
can be used by the developer to access the raw secret. You should never leak the token
.
To verify the secret, run the following command where key
and token
are replaced with the values from adding your secret
to the vault.
Expected output:
Below are some example HTTP Requests to a deployed Agent Contract without any changes made to the template.
Example
To debug your agent, you can use the following command:
After executing this command then you should see some output in the terminal to show the logs of requests to your agent.
To create logs in your Agent Contract, you can use the following syntax in your index.ts
file.
Running the local testnet may return an error if port 8000
is already in use.
Make a Request to Your Local Build
Add Secrets to Your Local Build
Check The Logs of Your Local Build
Congratulations! You have deployed and transacted on Base Sepolia! You now have the tools to connect to any top LLM API with the RedPill Agent Contract template and perform onchain actions with the viem
SDK.
Clone git repo or use to get the source code.
Note that your latest deployment information will be logged to in file . This file is updated every time you publish a new Agent Contract to IPFS. This file is also used to get the IPFS CID of your Agent Contract when setting secrets for your Agent Contract.
If ThirdWeb fails to publish, please signup for your own ThirdWeb account to publish your Agent Contract to IPFS. Signup or login at
Whenever you log into ThirdWeb, create a new API key and replace the default API Key with yours in the file.
Edit the file or create a new JSON file in the ./secrets
folder and add your secrets to it.
Note that all your secrets will be logged in file . This file is updated every time you add new secrets to your Agent Contract. If you have not published an Agent Contract, yet, this command will fail since there is not a CID to map the secrets to.
Note that if the transaction fails for the onchain transaction agent, try sending some test ETH to the of the Agent.
URL:
URL:
URL:
URL:
Check the for information on accessing URL queries
or body
from a post
request.
For more information check the on console
object.
Run a local testnet with . All you need to do to get a local testnet started is run: