0xedB0...3484

Turn your stories into NFTs

0 Following     0 Follower

CHRF: using Cherrific internal balance

This story was written when StoryPress was called Cherrific. It was a gas cost optimised version that turned out to be overly complicated. StoryPress does not use this internal balance concept any more, but I simple keep this story here as a remembrance of the past.

Cherrific is a publishing platform where you can write stories, comment and react on those stories. Each of these action will require you to burn one or more cherries: the CHRY token.

The CHRY token is a standard ERC20 token, managed by the smart contract that you can find here: 0x4C41bFf37db389BA1edC7ED7e757059a1D08ceb5

Each token transfer uses a bit more than 50 000 gas. When you make a comment, or react to an article, at least one CHRY is burnt, and at least one other is given to the author of the story. Hence, this will consume more than 100 000 gas, just for handling the CHRY transfers. This will end up rather costly if you do that often.

Here comes CHRF

In order to save gas, the Cherrific smart contract allows you to have an internal balance of cherries: they are kept inside the Cherrific smart contract for you, and are automatically used, instead of "external" CHRY tokens when you participate in Cherrific. That way, token transfers are around 5 times cheaper in gas.

These CHRY tokens that are kept for you inside the Cherrific smart contract have a symbol of their own: CHRF (for CHeRriFic).

They also have their own little logo:

CHRF token logo

Displaying your CHRF balance in MetaMask

Now here is a little trick: you can add the CHRF tokens that are kept for you in the Cherrific smart contract by clicking on the Balance button in the top bar, and click the MetaMask icon. This will prompt you to confirm that you want MetaMask to handle this token for you, and voilà. You can now see your internal CHRF token balance right from MetaMask. No need to go the Cherrific.io to check if you've earned cherries because someone has commented or reacted on one of your stories.

See your Cherrific internal balance in MetaMask

One more thing

The Cherrific smart contract fully implements the ERC20 token standard. That means that you can even transfer your CHRF tokens from inside your MetaMask to any other address.

Be aware that if you transfer CHRF to an address that is not yet a user of Cherrific, this will create its account. As any account creation costs 1 cherry (this entry cost is mainly here to deter fake accounts), this cherry will be taken from your balance.

It means that if you send 10 CHRF to a friend that is not a user of Cherrific yet, your friend will get his 10 CHRF, but you will spend 11 CHRF for the transfer.

Warning: Integers only

To save room, the Cherrific smart contract does not store decimals. This means that you can only transfert entire CHRF amounts. Just keep that in mind. Don't slice CHRF.

Are approve and transferFrom implemented too?

These two functions are part of the ERC20 token standard. So yes, they are implemented too. We don't really know what you could use them for, but if you need them, they are here for you to use.

Why did you bother?

Why did we bother implementing and testing these functionalities?

Well, as we first said, the main reason for having CHRF is to reduce gas cost for Cherrific's users.

The second reason is onboarding. To start using Cherrific (if you want to publish your first story, or make your first comment or add your first like), you need to:

  1. get some CHRY on SpookySwap (so you need to go there, and if you've never used this exchange, you will have to figure out how to use it)
  2. approve CHRY for Cherrific (this means allowing Cherrific smart contract to take some of your CHRY when you publish a story, comment, like, ...)

This might be easy for you, but maybe your grandmother will have a hard time doing all that. Instead of this SpookySwap + approve stuff, just send her some CHRF, and now she has everything needed to participate in Cherrific.

Any question? A comment? Something isn't clear? Please leave us a comment. If you like that article, or how we did our best to make onboarding as easy as possible, please consider leaving a like.

As you can see, a lot was done to make things as simple as possible. That goal was nevertheless not achieved. StoryPress now uses genuine cherry token transfers. The gas cost is a bit higher, which does not really matter on Fantom, where gas is so cheap, and the whole user experience is much simpler.

Reactions are currently disabled. They will return soon.

⏪ Previous Story

0xedB0...3484 avatar

Ethereum neutrality : worse that I had thought

In a previous article, Is Ethereum still neutral? I was asking about the fact that Ethereum might not be ...
by 0xedB0...3484

⏩ Next Story

0xedB0...3484 avatar

StoryPress.info getting responsive

StoryPress.info display has been very ugly on small screens so far. Here are the results of the work we did ...
by 0xedB0...3484