Token Reward Calculation:Staking Smart contract with Solidity.

A staking pool allows multiple stakeholders (or bagholders) to combine their computational resources as a way to increase their chances of being rewarded. In other words, they unite their staking power in the process of verifying and validating new blocks, so they have a higher probability of earning the block rewards. I will not explain the conception of staking deeply in here. Before a few days , my friend asked how to build staking platform by using solidity programming language which can build the smart contract .So I am going to focus the build of staking with smart-contract which was known well.

  • Solidity programming language
  • Openzeppelin-Solidity

As we can see in the picture, staking pool box has too many crypto assets and outputs the reward assets now as if the water comes out. But I only am going to deal one token.So future staking platform will offer token holders the ability to earn a passive income in exchange for staking their tokens and helping support the network’s infrastructure.

1.Token Contract building

Token name: HappyMoney

Symbol : HANEY

Total Supply: 100,000,000

Decimal: 18

Our Haney token will be released based on ERC20 standard token and will be exchanged by Uniswap exchange platform later.

So I am going to describe the token contract code simply in here.

pragma solidity ^0.8.0;

import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;

import “@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol”;

contract HaneyToken is ERC20, ERC20Detailed {

constructor(uint256 initialSupply) ERC20Detailed(“HappyMoney”, “HANEY”, 18) public {

_mint(msg.sender, initialSupply);

} }

When we create the token contract , we can give 100 M to initial supply and finally 100 M HANEY tokens will mint and they will be sent to a creator’s wallet. We assume we already have designed the Tokenomics to grow our token price value and to incentive the marketing . So let’s say we are going to allocate 10 M tokens for staking reward to stakeholders who give the influence to our network.

2.Staking Contract building

All stakeholders will participate to stake their token and they will get the some rewards to our token during some period .

They have to buy our tokens to stake through exchange sites. We will assume our Haney token is listing on the popular exchange sites after finish the presale round already.

  • APY (Annual percentage yield):40%
  • Stake fee : 1.5%
  • Unstake fee :0.5%

The detailed values will be used to calculate the staking reward amount as much as stake holders do stake. The stake holders can stake or unstake their tokens anytime.

At first time ,we are going to build the staking reward calculation like following.

Reward amount = Staked Amount * Reward Rate * TimeDiff / RewardInterval

  • Current staked Amount : staked amount *stake fee — unstaked amount *unstake fee
  • RewardRate : APY %
  • TimeDiff : current timestamp — last timestamp
  • RewardInterval: 365 days

So the stake holders will get reward amount by above calculation.

I didn’t describe the code in detail because I only wanted to let know how to implement staking reward calculation algorithm. Hopefully this article will help for smart contract beginners who are starting to build the staking contract. Thanks for reading my article. If you guys want to get full codebase. Please contact me here . Mail : jjg02016891@gmail.com

--

--

--

😀 Blockchain Specialist | Smart contract Developer

Love podcasts or audiobooks? Learn on the go with our new app.

CryptoBonusMiles gleam.io

Whitelist for $VULC IGO and Community pool is Live Now. Let’s Join!

PrivacySwap: How to Make Money During a Bitcoin Crash by DeFi Yield Farming and Vaults

Top 6 Crypto Exchanges for the Middle East Region

Pieta Review — Is the network worth the trouble?

Invest in Bitcoin, Even If It’s a Bubble: Leonid Bershidsky

We are changing our brand identity!

Interacting with Ethereum Smart Contract Events in Go with the Civil Events Crawler

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ding Tian

Ding Tian

😀 Blockchain Specialist | Smart contract Developer

More from Medium

Blocks — Available in Open Beta!

HLD Buy Back Announcement — Closing Holdefi Services

Taka Protocol: A Multichain Dex and Asset Management Protocol

Introduction to tokens and the Corda token SDK