ERC-3722 Poster: a general purpose social media contract (Poster)
Stagnant · Other · created 2021-07-31
An extremely simple contract that only takes two strings (content, tag) and records them as an event, allowing it to serve as a shared base layer for decentralized social media.
Why it is needed
Posting something like a tweet on Ethereum usually requires each app to build its own dedicated contract and store posts in storage. This drives up gas costs, and because every app has a different event structure and data format, indexers must integrate separately for each app. Different contract addresses on different networks also create confusion over which address wallets or apps should trust. Without a shared standard like Poster, the same basic 'write a post' function gets redesigned by every project, and the indexing and discovery work needed to aggregate and display post data has to be rebuilt each time.
What to implement
event NewPost(address indexed user, string content, string indexed tag);: An event that records the author's address (user), the post content (content), and a tag (tag). user and tag are indexed and can be used for search, but content is not indexed.function post(string calldata content, string calldata tag) public {: A function that anyone can call; when called, it emits the received content and tag together with msg.sender as a NewPost event.
In depth
Contract structure
The Poster contract has no state variables at all, and only one event, NewPost, and one function, post. post(content, tag) is a public function anyone can call, and executing it runs only a single line, emit NewPost(msg.sender, content, tag). In other words, it stores no state on chain at all, only leaving the sender, content, and tag at call time as a log.
Event indexing design
In the NewPost event, user (address) and tag (string) are declared as indexed, so logs can be filtered and searched by a specific author or tag. content (string), on the other hand, is not indexed, so the full text is stored as is in the log data. The ABI likewise specifies indexed:true only for user and tag.
Standard JSON post format
The original text also proposes a JSON format for Twitter-like apps. Multiple posts/actions can be packed into a single post() call inside the content array. If type is microblog, it can have text, a reply target replyTo, an image field, and an edit target edit; other types such as delete, like, repost, follow, unfollow, block, and report specify a target. The permissions type grants permissions to other accounts via an account field and boolean values for each of post/delete/like/follow/block/report/permissions. An account that has been granted permission can specify a delegated author via the from field on a microblog post.
Why the post ID is not emitted
According to the original Rationale, there was discussion about including a post ID in the event, but it was decided not to include one because doing so would add state and complexity to the contract. Instead, the common pattern of assigning an ID at the indexer layer by combining transactionHash and logIndex is used.
Why bytes was not used instead of string
content is emitted as a string rather than bytes so that existing interfaces like Etherscan can display it in human-readable form directly. This sacrifices the gains that could have been achieved with a more compact encoding like CBOR, but the explanation is that the requirement for human readability could not be satisfied with CBOR.
Why content is still emitted
Emitting nothing at all would have saved gas, but it would have sharply increased the node requirements needed to index posts. For this reason, it was judged better to emit the actual content even at the cost of extra gas.
Reference implementation and deployment method
Poster is deployed at address 0x000000000000cd17345801aa8147b8D3950260FF on multiple networks using the Singleton Factory (EIP-2470). On chains where it has not yet been deployed, it can be deployed to the same address by submitting the initCode and salt values given in the original text to the Singleton Factory. When verifying the source code on a block explorer, the optimizer must be set to yes with runs set to 10000000.
Current status
This ERC is marked as Stagnant, meaning it is a proposal where discussion has stalled with no further progress.
Things to watch out for
- Low risk because the contract itself is simple: Because the implementation is extremely simple, the spec states there are no substantive security issues at the contract level.
- Possibility of a forged from field: If post data contains a from field that differs from msg.sender, clients must verify whether that from address actually granted that permission via a permissions post. If it cannot be verified, it should be treated as invalid or attributed to msg.sender themself.
- Sanitizing post data: Clients must sanitize post data read from the chain.