Create A Front End
Last updated
Last updated
If you would like to use a pre-built front end, we've built an open source React UI that you can clone and deploy.
If you prefer to build your own front end instead, this page will explain everything you need to know about which contract tables and actions you'll need access to, in order to show users the proper info.
For partners - user facing actions on the tf.waxdao
contract are covered on the Staking Page. Creator facing actions for your partner contract are covered in the README file of the partner contract.
In order to show what a users claimable balances are in a current farm, there is no need for you to do any math on your front end. We've created a readonly
action on the tf.waxdao
contract, which returns a vector of claimable assets to you in the form of extended_asset
The action is showreward
, and takes in the following data.
user
name
The WAX address of the user to get data for
farm_name
name
The name of the farm to show rewards from
An example of fetching this data is shown below.
The best way to do this is by using the /staked-only
endpoint in our API Documentation. If you prefer to query directly from the chain, you can query the stakers
table.
The stakers
table on the tf.waxdao
contract is scoped by user. If you want to display which farms that user is staked in, all you need to do is call get_table_rows
and set user.value
as the scope. This will return you a list of all farms that they are staked in.
Keep in mind that this will only show staking details, and farm data will need to be fetched separately. This is why using our API is recommended instead.
We recommend using our custom API for this, by calling the /get-farms
endpoint. If you want to query directly from the chain, you can query the farms
table.
The farms
table on the tf.waxdao
contract has a secondary index by creator
. An example using a custom React hook is shown below.
It is important to note that if you are a partner, you are the creator of all farms created using your partner contract. In order to show users which farms they created using your partner contract, you also need to fetch the farms
table from your own contract, and then filter
the farms returned by the first get_table_rows
call, based on who the current user is.
We recommend avoiding this messy logic by just using our API instead, or building your own.
Farm creators are able to set a locking period when users stake in their farm. It is important that you show this vesting period on your front end, so users can be aware if they are about to lock tokens when they stake.
You can also display a user's current unlock time for existing stakes, by showing the vesting_end_time
which is tracked in the user's row for each farm. It's an epoch timestamp, so it needs to be converted into a human readable date.
While the getreward
action exists on the tf.waxdao
contract, and not the partner contract, it is worth mentioning something here.
The getreward
action returns a vector of extended_asset
, giving you real time information about the amounts that were claimed.
You can use this data to show a user exactly how much of each asset they received in the transaction modal. While this might seem redundant since you can show them how much they are about to claim, rewards are paid out by a farm every second. Which means that by the time the transaction is pushed, the user may actually receive slightly more tokens than the amounts you displayed beforehand.
Regardless, UX is important and people will enjoy seeing the output of the transaction. Either that, or I just like action return values too much and wanted to find a use case for them