Introduction: ERC-20 and Smart Contracts
Recently Publish0x users have been given another avenue to both generate and receive tips, for creating/consuming content, in the form of Loopring tokens (LRC). LRC are an ERC-20 tokens that were developed to support the blockchain transactions carried out on the Loopring protocol. ERC-20 tokens operate on the Ethereum platform and must adhere to the following criteria:
- totalSupply - identifies the total number of ERC-20 tokens created.
- balanceOf - function is carried out, it returns the number of tokens a given address has in its account.
- transfer - allows a certain number of tokens to be transferred from the total supply to a user account.
- transferFrom - is the function that allows a user to transfer tokens to another user.
- approve - checks a transaction against the total supply of tokens.
- allowance - function checks the balance of the user’s account and will cancel the transaction if there are insufficient tokens.
You may ask why am giving a bit more detail about the ERC-20 tokens but it is important to be aware of how these are generated. These tokens are created by smart contracts. But also smart contracts are used to perform transactions with an ERC-20 token. The process by which we're going to stake LRC is no different, it is just a string of smart contracts to send tokens to a specific staking address and stake our tokens. Claiming and withdraw are also carried out by a smart contract, so by learning how this process works manually you will start to gain an understanding of how the whole processes of interactions are done on the ETH network.
Introduction: LRC Staking
Loopring successfully deployed the version 3.0 of the protocol and with it came the ability to stake tokens. Staking of LRC tokens will help to secure and maintain the network and comes in three distinct flavors each with their own benefits:
- General staking which anyone can take part in (what we're going to focus on later). This will lead to a return on the staked amount as a portion of 70% of the protocol fees of all exchanges built on top of Loopring
- Exchange security and reputation staking, where an exchange owner stakes LRC for economic security & reputation. This is actually a really cool, feature, it has been implemented as a means to prevent new/existing DEX from making use of the Loopring protocol without having a 'horse in the race'. Should a DEX mistreat users funds or attempt malicious activity it gives Loopring an avenue to effectively financially sanction them as they have committed fund to support the network.
- Fee Reduction Staking, where high volume/frequency traders or exchanges can stake in order to reduce reduce protocols fees on a specific exchange
As a Publish0x content creator and partial investor in LRC now is a great opportunity to take a look at how I can support this network actively and get my LRC tokens to work for me by earning a portion of the redistributed fees that filter down to encourage healthy maintenance.
Before we dive into the How-To portion of this guide I'm going to make a few brief prerequisites and also give a general warning. This process is currently quite clunky as it doesn't have a tidy front end application like Tezos baking for example. If you're going to try it make sure you set aside some time and perhaps try with a small amount first before going all in. Also remember this isn't financial advice, I'm giving this guide simple as a fun learning tool and going through the steps myself so that you don't have to if you don't want to. Anyways, enough of the intro, lets get staking!
Step 1: Wallet
Firstly, I'm going to assume you have the Brave browser, the reason I say that is we're going to stake from our crypto wallet that is built into the Brave browser. If you don't have Brave yet, it is an ideal choice for you as a Publish0x read/contributor as it offers a direct platform where you can withdraw your tips in an easy and secure way. Here is my referral link if you still need to download it: https://brave.com/myn040. Alternatively, if you use meta mask then the process should work with that.
I''ll write a short separate guide for setting up and withdrawing to from Publish0x to the Brave integrated wallet, to avoid this one getting too busy, it is detailed enough with too much additional information. If you're withdrawing to Mycrypto, MetaMask or other ETH addresses then here is a great guide to follow: https://www.publish0x.com/earning-that-crypto/how-to-withdraw-publish0x-payments-publish0xtutorials-xodkyw
Step 2: Staking
The staking process to two main step, firstly we'll need to send tokens to the Loopring network's staking pool address (below). The transactions of this address can be seen here: https://etherscan.io/address/stakingpool.lrctoken.eth. Once sent we will need to create another contract to commit the tokens to staking. It is important to note here that staking tokens takes 90 days, so have that in mind when you start the process. Also remember you need a bit of ETH in your account to facilitate the transaction fees, not a lot but some.
Pool address: 0xF4662bB1C4831fD411a95b8050B3A5998d8A4A5b
Contract 1: Sending funds
- 1 - Navigate to etherscan.io/address/lrctoken.eth#writeContract this is where we're going to write the first contract.
- 2 - Scroll down the page and find the 'Connect to Web3' we're going to use this to connect our wallet to be able to perform transactions from that address
- 3 - You'll get a smaller separate window pop up which will ask you to log into your wallet through Brave (a), afterwards it will confirm you're happy to connect etherscan.io to your wallet (b)
- 4 - In addition you may also get a warning that etherscan.io is currently a beta version, remember we're using this at our own risk
- 5 - Back on the contract page we can now start to decide what funds we're going to send to the staking pool:
- a) If all went well connecting the wallet you'll see a green dot next to 'Write Contract'
- b) First we'll enter the pool address in remember this is where we're actually sending funds they will leave your wallet. The address is 0xF4662bB1C4831fD411a95b8050B3A5998d8A4A5b, double and triple check you've got that one right
- c) Then we can answer how much we want to send (i.e. how much we're going to stake). This is entered as [Amount] concatenated with  that is 18 zeros. So for me it was +
- 6 - After entering the details and re-checking it we can click 'Write' which will pop-up another Brave notification window for us that will show the cost in ETH to submit the smart contract (remember there is always a transaction fee for performing actions on the blockchain). Click confirm to continue.
- 7 - Now we should wait before moving to the second contract, we need to make sure that this first transaction has completed. It should only take a few mins. You can double check your crypto wallet in Brave and make sure it shows "Approved"
Contract 2: Staking funds
- 1 - Once the first contract is complete we need to navigate to etherscan.io/address/stakingpool.lrctoken.eth#writeContract this is where we're going to write the second contract (where we commit the tokens to staking).
- 2 - As with the previous contract we need to start by connecting our wallet
- 3 - Now we need to scroll down to the staking section '6. stake' and here we'll enter the same amount that we sent to the pool [Amount]+ and click on write.
- 4 - Again we're going to have a fee for performing this action, click confirm to continue
- 5 - Note here that when we go back to the contract page the 'View your transaction' button will have become active, we'll click this and look at the details below.
Step 3: Checking on your funds
As we saw in the previous step after writing the second contract we got the option to view the transaction. Do so gets you a nice tidy summary of the transaction information. This includes, the block, timestamp, sending/receiving addresses, tokens and value at given time as well as the transaction fee.
However, we're also going to want to be able to review the status of our stake, remember I said it takes 90 days so we need to know when it will complete as well as the current status of the fund. We do this by querying (or reading) the contract, this is how we do it:
- 1- Navigate to etherscan.io/address/stakingpool.lrctoken.eth#readContract
- 2- Then, in the section '1. getUserStaking':
- a) Enter your ETH address (where the tokens originated from) and click on 'Query'
- b) The details of the stake will be presented the important information here is withdrawalWaitTime which is in seconds ((7766883/60)/60)/24 = 89.89 days
Bonus item for websites:
So I had a quick look online and was able to immediately find a tidy little widget for a countdown that can be added to your websites if you have one. I just thought it would be a nice way to track the stake with some degree of accuracy without having to query the contract constantly.
- Go to timeanddate and enter the start date/time of your contract here: https://www.timeanddate.com/date/timeadd.html?type=add&ad=90 (you can use the timestamp from the transaction info as above).
- Then go to https://www.timeanddate.com/clocks/freecountdown.html and create you own widget
- If you want to see it in action then head over to my site and see the quick stake counter I set up in the footer: https://mynima.github.io/
Step 4: Claiming/Withdraw your Stake
As my current stake is ~90 days from being available I'll take through the claiming/withdrawing steps quickly but with a lot less pictures since I will not fully perform these actions yet.
- 1 - First we need to navigate to the contract etherscan.io/address/stakingpool.lrctoken.eth#writeContract and, as always, connect our wallet
- 2 - Go to the section '2. claim' and click on write.
- 3 - You'll get a Brave notification indicating the transaction fee amount and, if your stake is ready then you'll claim your reward.
- 4 - Finally if you want to withdraw your funds simply complete the '1. withdraw' amount box (remember the 18 zeros) and click write. As with the previous step there will be a fee.
If everything went well we can say Congratulations, you Staked LRC! But also I would say, if you persevered with this process then a massive congratulations for having a go and successfully writing some basic smart contracts, this has been a really fun process to have a go at and I hope you also enjoyed it.
Before we close out I will say there is an additional bonus to folks who stake on the network in these early days. This is to be distributed on/around 01-May-2020, so keep your eyes peeled and if you plan on having a go maybe now is a good opportunity. Remember though you lock in your funds for 90 days so only lock down what you are not planning on using.
Hope you enjoyed the guide, good luck y'all!