A simple, decentralized Twitter-like application built with Solidity. Users can create tweets, like/unlike them, and fetch tweets by user. The contract also includes access control for managing platform-wide tweet constraints.
- π Post tweets with a configurable character limit (default: 280)
- β€οΈ Like and Unlike tweets
- π View single tweets or all tweets by a user
- π Only registered users (via profile contract) can interact
- βοΈ Owner-only access to adjust platform settings
- Solidity
^0.8.0 - OpenZeppelin Contracts
- Compatible with Hardhat or Foundry
Defines the structure of a tweet:
idβ Unique tweet ID (per user)authorβ Address of the tweet authorcontentβ The tweet texttimestampβ When the tweet was createdlikesβ Number of likes
| Function | Description |
|---|---|
createTweet(string _tweet) |
Creates a tweet if within character limit and user is registered |
getTweet(uint _i) |
Fetches the i-th tweet of the sender |
getAllTweets(address _owner) |
Fetches all tweets by a specific user address |
| Function | Description |
|---|---|
likeTweet(address author, uint256 id) |
Like a specific tweet from another user |
unlikeTweet(address author, uint256 id) |
Unlike a tweet (if it has likes) |
| Function | Description |
|---|---|
getTotalLikes(address author) |
Returns total likes across all tweets by a user |
| Function | Description |
|---|---|
changeTweetLength(uint16 newTweetLength) |
Update max allowed tweet length (default: 280) |
| Event | Description |
|---|---|
TweetCreated(uint256 id, address author, string content, uint256 timestamp) |
Emitted when a tweet is created |
TweetLiked(address liker, address tweetAuthor, uint256 tweetId, uint256 newLikeCount) |
Emitted when a tweet is liked |
TweetUnliked(address unliker, address tweetAuthor, uint256 tweetId, uint256 newLikeCount) |
Emitted when a tweet is unliked |
- Inherits from OpenZeppelin's
Ownable - Only the contract owner can modify
MAX_TWEET_LENGTHusingchangeTweetLength - Only registered users (those with a non-empty
displayNamein theIProfilecontract) can:- Create tweets
- Like tweets
- Unlike tweets
// Create a tweet
twitter.createTweet("Hello Web3!");
// Like a tweet
twitter.likeTweet(address_of_author, tweet_id);
// Get all tweets from a user
Tweet[] memory myTweets = twitter.getAllTweets(msg.sender);This project is licensed under the MIT License.
Built with β€οΈ using Solidity.
Feel free to contribute or fork the project!