Skip to content

Yaswanth-Vempuluru-7916/Twitter-DApp

Repository files navigation

Twitter DApp

X DApp UI

A decentralized Twitter-like application built on Ethereum blockchain, allowing users to create, like, and unlike tweets in a trustless environment.

Features

  • Connect to MetaMask wallet
  • Create tweets that are stored on the blockchain
  • View your tweets
  • Like and unlike tweets
  • Event emissions for all interactions

Technologies Used

  • Solidity (Smart Contract)
  • Web3.js (Blockchain Interaction)
  • HTML/CSS/JavaScript (Frontend)
  • Ethereum (Blockchain)

Getting Started

Prerequisites

  • MetaMask browser extension installed
  • An Ethereum account with some ETH for gas fees (can use testnet)

Installation

  1. Clone this repository:

    git clone https://github.com/yourusername/twitter-dapp.git
    cd twitter-dapp
  2. Create a config.js file in the root directory with your contract address:

    const CONFIG = {
      CONTRACT_ADDRESS: "0xB0e..."  // Replace with your actual contract address
    };

    Note: config.js is included in .gitignore for security reasons. Never commit your contract address or private keys to public repositories.

  3. Open index.html in your browser or use a local server:

Smart Contract

The Twitter contract provides the following functionality:

  • createTweet(string memory _tweet): Create a new tweet
  • likeTweet(address author, uint256 id): Like a tweet
  • unlikeTweet(address author, uint256 id): Unlike a tweet
  • getTweet(uint _i): Get a specific tweet
  • getAllTweets(address _owner): Get all tweets from a specific address

Events

The contract emits the following events:

  • TweetCreated(uint id, address author, string content, uint timestamp)
  • TweetLiked(address liker, address tweetAuthor, uint tweetId, uint newLikeCount)
  • TweetUnliked(address unliker, address tweetAuthor, uint tweetId, uint newLikeCount)

File Structure

twitter-dapp/
├── index.html         # Main HTML file
├── styles.css         # CSS styles
├── index.js           # Frontend JavaScript
├── config.js          # Configuration file with contract address (gitignored)
├── abi.json           # Contract ABI
├── Twitter.sol        # Solidity smart contract
└── README.md          # This file

Configuration

To set up your own instance of this DApp:

  1. Deploy the Twitter.sol contract to Ethereum (mainnet or testnet)
  2. Create the config.js file with your deployed contract address:
const CONFIG = {
    CONTRACT_ADDRESS: "0xYourDeployedContractAddress"
};

Usage

  1. Open the application in your browser
  2. Click "Connect Wallet" to connect your MetaMask
  3. Type your message in the textarea and click "Tweet" to create a new tweet
  4. View your tweets in the "Your Tweets" section
  5. Like or unlike tweets using the respective buttons

Security Considerations

  • The contract owner can change the maximum tweet length
  • Tweets are publicly visible on the blockchain
  • User interactions cost gas

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

  • Ethereum community
  • Web3.js developers
  • Solidity developers

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published