What is Staking and what I learned from launching a Staking dApp?

Damodarbihani
5 min readJul 10, 2023

--

The Staking Ecosystem of the top blockchains. Source.

What is Staking?

Staking is a process in which cryptocurrency holders can earn rewards by locking up their tokens and participating in the validation of transactions on a blockchain network. Staking is a way to secure the network and ensure that transactions are processed fairly and efficiently while following the guidelines of the consensus mechanism.

Staking is a key feature of proof-of-stake (PoS) blockchains, which are a more energy-efficient alternative to proof-of-work (PoW) blockchains. PoW blockchains, like Bitcoin, require miners to use powerful computers to solve complex mathematical problems in order to add new blocks to the blockchain. This process consumes a lot of energy and can be expensive. PoS blockchains, on the other hand, allow anyone to participate in the validation of transactions by staking their tokens.

To stake tokens, you need to create a staking wallet and deposit your tokens into it. Once your tokens are in your staking wallet, you can choose to delegate them to a “validator” or run your own validator node. Validators are responsible for validating transactions and adding new blocks to the blockchain. They are rewarded with a portion of the transaction fees for their work and in case they submit fraudulent transactions, they are punished by getting their stake slashed.

A Breakdown of the staking entities for the highest market-cap PoS blockchain, Ethereum. Source

Lessons learned from launching the dApp

I created a Staking dApp and launched it on my localhost because I am a huge believer in learning by doing. Even though I’m still a beginner at coding, platforms like Scaffoldeth & Alchemy University have great tutorials where you learn through follow-along guides. Scaffold eth gives an off-the-shelf sort of stack for rapid prototyping on Ethereum and Alchemy is the ultimate ecosystem for learning how to build and interact with web3. The code for the dApp can be found here.

The main bareback UI of the staking dApp obtained by spinning up Scaffold ETH on the local testnet. .5 ETH has been locked in the Staker Contract in this instance.
7 ETH has been accrued as interest during the lockup period with the reward rate of .1 ETH/sec as can be seen in the withdrawable balance contract

The parameters followed while creating the dApp:

  1. Only expect a single user to interact with the staking dApp.
  2. Need to be able to deposit and withdraw from the smart contract. Furthermore, the withdraw function from the contract removes the entire principal balance and any accrued interest.
  3. The smart contract has an interest payout rate of 0.1 ETH for every second that the deposited ETH is eligible for interest accruement. Also, no re-staking of the balance is allowed.
  4. Upon deployment, the contract begins with 2 timestamp counters. The first deadline is set to 2 minutes and the second is set to 4 minutes. Other criteria to be considered:
  • The longer you deposit the money, the more interest you get.
  • Only during certain time windows deposits and withdrawals can be made.
  • Unproductive capital is disincentivized so that a user actively engages with the protocol.
  • Any funds left are locked in an external contract that is already pre-installed in the Scaffold-Eth environment.

Some important Solidity concepts learned while deploying the dApp include:

  • Modifiers: These are used to change or restrict the behavior of a function in a smart contract
  • Constructors: These are special functions that are called when a smart contract is deployed. They are used to initialize the state of the contract, such as setting the values of variables or creating new objects.
  • Solidity Mappings: These are a type of data structure that stores data in the form of key-value pairs. The key can be any of the built-in data types supported by Ethereum, and the value can be of any type.
The working UI to interact with the Debug Contract which includes starting timestamps of the contract.

Some of the benefits of staking include:

  • Earn passive income: Staking is a way to earn rewards without having to actively trade or sell your tokens.
  • Secure the network: Staking helps to secure the network by encouraging users to participate in its validation.
  • More energy-efficient: PoS blockchains are more energy-efficient than PoW blockchains.
  • Scalability: PoS blockchains, in theory, as compared to other consensus mechanisms, can support more simultaneous transactions without compromising security or decentralization.
  • Increase Participation: PoS opens the door to more users participating in blockchain systems as validators since there’s no need to buy expensive computing systems or consume massive amounts of electricity to stake crypto.
There’s been a gradual increase in user participation as validators for securing the Ethereum Blockchain. Source.

Some of the risks of staking include:

  • Impermanent loss: When you stake tokens, you are essentially locking them up for a period of time. If the price of the token goes down during this time, you may experience impermanent loss.
  • Slashing: If you are a validator and you act maliciously, you may be slashed, which means that you will lose some of your tokens.
  • Security risks: Staking wallets are often targeted by hackers. It is important to choose a reputable staking platform and to take steps to secure your wallet.
  • Validators who hold large amounts of a blockchain’s token or cryptocurrency may have an outsized amount of influence on a proof of stake system.

Overall, staking is a relatively new and innovative way to earn passive income and help to secure the network. The Proof of Stake blockchain consensus mechanism implementation is gaining traction due to its lower energy demands and increased accessibility for everyday people to participate in validation.

--

--