Mimo Log #2: Contract Storage is a Mofo
Neat Tricks for Circumventing Expensive Storage Costs
I’m documenting some of the challenges behind building Mimo. I figured it would be a nice way to keep the community updated and start a discussion about how to build decentralized networks without moving too fast or breaking things à la Facebook.
Welcome to the second installment of Mimo logs.
Last time, I mentioned how high gas costs were and the technical problems behind an idea like Mimo. Well I’d like to report that I’ve found great solutions to those problems and will be ready to open up a beta test for Mimo by the end of July.
I talked about the tactics I used to lower gas costs significantly in this Twitter thread so go ahead and read that (and follow me while you’re at it ), it’s 9 tweets.
9 tweets is too many for you? Well to recap, I’ll be using a stateless design in my smart contract to save on gas costs. Essentially, that means logging all data in events.
How does that help you ask? Well say we wanted to know if a profile follows another profile (let’s call them A and B). We don’t necessarily need contract storage to tell us that A follows B, all we need is proof that our follow()
function was called by A with B as a followed profile. If we put an event at the end of our function and pass the params from the follow()
then we just have to fetch the latest follow event to see that A follows B.
Here’s an example:
contract Mimo { event Follow(uint256 indexed _this, uint256 indexed _that, bool indexed _response); function follow(uint256 _this, uint256 _that) public { Follow(_this, _that, true); } function unfollow(uint256 _this, uint256 _that) public { Follow(_this, _that, false); }
Using web3.js, we can query the blockchain and fetch the latest Follow
event with filters for _this
and _that
and see what kind of _response
we get, which will tell us if _this
follows _that
.
My idea for keeping Mimo as decentralized as possible while still keeping gas costs low is using Stateless design in my contracts and having every Dapp that integrates Mimo into their Dapp use the mimo.js library that I will be releasing to facilitate querying the smart contract’s event logs.
Next issue is on smart contract upgradeability. Hope you enjoyed the second issue of Mimo Log, see y’all next time!