Skip to main content

Integrate Twitter Agent Service into Your Enclave Application

This guide will walk you through seamlessly integrating the Twitter Agent service into your enclave setup and leveraging its APIs to interact securely with the encumbered account from within the enclave.

1. Set Up Environment Variables

Create environment variable files with all the required details.

.env

USERNAME=                      # Username for the twitter account 
USER_EMAIL= # Email associated with the twitter account
X_APP_NAME= # Name of the application on X developer portal

.env.secrets

OPENAI_API_KEY=                # API key for OpenAI services  
USER_PASSWORD= # Password for the twitter account
USER_EMAIL_PASSWORD= # Password for the email account

.env.twc

CONTRACT_ADDRESS=             # TweetWithOysterAgentService contract address
PORT= # Port for the tweet with contract application

.env.twc.secrets

RPC_URL=                      # RPC url for the network

2. Configure Services in docker-compose.yml

Add the following services and volumes to your docker-compose.yml file:

services:
twitter_agent_service:
image: sagarparker/twitter_agent_service_amd64:latest
init: true
restart: unless-stopped
network_mode: host
command: ["/opt/venv/bin/python", "/app/x_agent.py"]
volumes:
- /init-params/:/init-params/
- shared_data:/app/shared_data
env_file:
- /init-params/.env
- /init-params/.env.secrets
verifier:
image: sagarparker/twitter_agent_service_amd64:latest
init: true
restart: unless-stopped
network_mode: host
command: ["/opt/venv/bin/python", "/app/verifier.py"]
volumes:
- /init-params/:/init-params/
- shared_data:/app/shared_data
env_file:
- /init-params/.env
- /init-params/.env.secrets
volumes:
shared_data:

3. Deploy the Application with Oyster-CVM

Use the following command to deploy your application with oyster-cvm:

oyster-cvm deploy --wallet-private-key **** --duration-in-minutes 60 --arch amd64 --docker-compose docker-compose.yml --instance-type r6i.xlarge  --init-params ".env:1:0:file:.env" --init-params ".env.secrets:0:1:file:.env.secrets" --init-params ".env.twc:1:0:file:.env.twc" --init-params ".env.twc.secrets:0:1:file:.env.twc.secrets"

Note: You can specify additional initialization parameters for your application by adding more --init-params flags.


4. Generate and Retrieve Access Tokens

Securely generate and fetch access tokens within Oyster Enclaves using the following API endpoints:

curl {oyster-enclave-ip}:{tweet-with-contract-port}/generate_access_keys
curl {oyster-enclave-ip}:{tweet-with-contract-port}/start_listening_for_tweet_events

5. Verify Encumbrance

Once deployed, verify the encumbrance using the following endpoint:

curl {oyster_enclave_ip}:8888/verify_encumbrance

Conclusion

In this guide, we explored how to integrate the Twitter Agent service into your enclave setup, enabling secure access to the encumbered Twitter account within the Oyster TEE. 🚀