A decentralized Twitter-like application built on Ethereum blockchain, allowing users to create, like, and unlike tweets in a trustless environment.
- Connect to MetaMask wallet
- Create tweets that are stored on the blockchain
- View your tweets
- Like and unlike tweets
- Event emissions for all interactions
- Solidity (Smart Contract)
- Web3.js (Blockchain Interaction)
- HTML/CSS/JavaScript (Frontend)
- Ethereum (Blockchain)
- MetaMask browser extension installed
- An Ethereum account with some ETH for gas fees (can use testnet)
-
Clone this repository:
git clone https://github.com/yourusername/twitter-dapp.git cd twitter-dapp
-
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. -
Open
index.html
in your browser or use a local server:
The Twitter contract provides the following functionality:
createTweet(string memory _tweet)
: Create a new tweetlikeTweet(address author, uint256 id)
: Like a tweetunlikeTweet(address author, uint256 id)
: Unlike a tweetgetTweet(uint _i)
: Get a specific tweetgetAllTweets(address _owner)
: Get all tweets from a specific address
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)
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
To set up your own instance of this DApp:
- Deploy the Twitter.sol contract to Ethereum (mainnet or testnet)
- Create the
config.js
file with your deployed contract address:
const CONFIG = {
CONTRACT_ADDRESS: "0xYourDeployedContractAddress"
};
- Open the application in your browser
- Click "Connect Wallet" to connect your MetaMask
- Type your message in the textarea and click "Tweet" to create a new tweet
- View your tweets in the "Your Tweets" section
- Like or unlike tweets using the respective buttons
- The contract owner can change the maximum tweet length
- Tweets are publicly visible on the blockchain
- User interactions cost gas
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Ethereum community
- Web3.js developers
- Solidity developers