Skip to main content

Step 3 : Deploy on Oyster CVM

In this step, we will deploy a Node.js application on Oyster CVM that seamlessly listens for tweet events from a Solidity smart contract and automates the posting of paid tweets using an encumbered account. Leveraging the power of the Twitter Agent Service, it ensures secure tweeting.


1. Clone the tweet with contract repo

git clone https://github.com/marlinprotocol/tweet-with-contract

2. Smart Contract Deployment:

Deploy the TweetWithOysterAgentService.sol smart contract on the network of your choice.

Note: The TweetWithOysterAgentService contract charges 0.0001 ETH per tweet and sends the fee to the contract deployer.

3. Setup the environment variables files

Inside the repo, create these four environment variables files in your project's root directory

.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

Ensure that you correctly fill in the values for all required variables before proceeding.

4. Deploy on Oyster CVM

Deploy in Production Mode

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"

5. Usage

1. Generate Access Tokens

Generate access tokens inside the enclave by calling the following endpoint:

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

Note: This endpoint does not return the API keys or access tokens. It only generates them inside the enclave.


2. Start Listening for Tweet Events

Start listening for tweet events inside the enclave by calling the following endpoint:

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

3. Post a Tweet via the Smart Contract

Call the tweet function from the deployed smart contract to post a tweet. You can use a explorer or a tool like Remix to interact with the contract.

  • Example: Write Contract on Arbitrum Sepolia
  • Parameters:
    • tweetContent: The string to be posted on Twitter.
    • Value: Ensure to send at least 0.0001 ETH with the transaction.

4. Verify encumbrance using the following endpoint

curl {oyster_enclave_ip}:8888/verify_encumbrance

This endpoint provides the following guarantees:

  1. The password for the Twitter account is known only to the enclave.
  2. The password for the email account is known only to the enclave.
  3. The Twitter account cannot be recovered as there is no backup email and the email matches the provided email ID.
  4. There is only one app on the X developer portal, and its name matches the enclave-provided app name.
  5. The access tokens and API keys for the twitter account were regenerated.

Conclusion

By following this guide, you have successfully:
✅ Deployed the TweetWithOysterAgentService smart contract on your chosen network.
✅ Configured the required environment variables for the Twitter Agent Service.
✅ Deployed the Node.js application on Oyster CVM.
✅ Generated access tokens and API keys securely within the enclave.
✅ Automated the posting of tweets through the smart contract while ensuring the security of sensitive credentials.