Token Staking Template

Create Aptos Dapp Token Staking Dapp Template

The Token staking dapp template provides an end-to-end Fungible Asset staking dapp.

With this dapp, you can:

  1. Create an incetivize pool on Aptos.
  2. Modify a pre-made UI to build a Staking dapp users can quickly adjust.
  3. Learn how to write a Move contract and front end connected to that contract.

If you have not created a fungible asset yet, check out the Token Minting Dapp Template to easily create a token on Aptos.

The Token staking dapp template provides a one page with different components:

  1. Create an incetivize pool - A component for the stake creator to create an incentivize (rewards) pool
  2. Stake Fungible Asset Component - A component for anyone to stake the fungible asset
  3. Unstake Fungible Asset Component - A component for any staker to unstake the fungible asset
  4. Claim fungible assets rewards - A component for any staker to claim the fungible asset rewards

Quick Start

Generate the Token Staking dapp template

On your terminal, navigate to the directory you want to work in and run:

Follow the CLI prompts.

If you are using the Testnet network, you will need to fund a module publisher account manually through the faucet web view on https://aptos.dev/en/network/faucet and then fill out the MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY and MODULE_PUBLISHER_ACCOUNT_ADDRESS in your project .env file.

Publish the Move Contract

In the .env file, set VITE_REWARD_CREATOR_ADDRESS to be the same as your account address.

This determines which account is allowed to create a pool using the dapp.

If you haven't set up an account, you can create one with an Aptos wallet like Petra. Make sure to set up the account on the same network as your template project.

For example:

In the .env file, set VITE_FA_ADDRESS to be the same as the fungible asset address.

This determines which asset is used as the stake asset.

If you have not created a fungible asset yet, check out the Token Minting Dapp Template to easily create a token on Aptos.

For example:

On the project root folder, run the below command to publish the contract.

You will have to confirm the gas fee in the console.

This command will:

  1. Publish the contract to chain.
  2. Setting the VITE_MODULE_ADDRESS in the .env file to set the contract object address.

Incentivize the pool with rewards

After you have published the Move contract to chain

Run the app and open the preview.

In the top-right corner, click "Connect a Wallet".

Use the same account that you set in .env for the VITE_REWARD_CREATOR_ADDRESS. Or, if you use a different account, set the VITE_REWARD_CREATOR_ADDRESS to the account you sign in with and republish the contract.

Click the Add Incentivize button

Once you are connected with the same account that you set in .env for the VITE_REWARD_CREATOR_ADDRESS, you should be able to see the Incentivize Pool component with a Add Incentivize button.

Clicking the button pops up a modal for you to enter the incentivize pool duration (in weeks) and the amount of the fungible asset.

Once you approve the transaction, you have successfully created an incentivize pool on Aptos!

Customizing the Front-End

Most data on the front end is customizable in frontend/config.ts.

Modify static content

Once the collection address has been configured, view the frontend/config.ts file to change any static content on the page. You can also modify the code itself as you wish.

How to add static images?

The public mint page uses static images in the UI. Initially, the images are imported from the frontend/assets/placeholder folder. To use custom images, you should add the image you want to use to the frontend/assets folder (under any new folder you want to create) and then import the image as seen below in the frontend/config.ts file and add it under the section you want to have it.

How can I take it from here?

Remember, one of the goals of this template is to educate and provide a real life example on how a Fungible Asset staking dapp can be on Aptos. We provide some basic concepts and features but there is much more you can do for your dapp.

Some ideas you can try are:

  1. Choose different fungible assets for the staked token and the reward token.
  2. Custom flows after someone stakes an asset
  3. Check out our TS SDK to see what other API queries you can use to support more features and fetch more data.

Ready for Mainnet

If you started your dapp on testnet, and you are happy with your asset testing, you will want to get the asset on mainnet.

Creating a asset on mainnet is the same flow as creating on testnet, but we need to change some configuration.

Note: Make sure you have created an existing account on the Aptos mainnet

  1. Change the VITE_APP_NETWORK value to mainnet on the .env file
  2. Update the VITE_MODULE_PUBLISHER_ACCOUNT_ADDRESS to be the existing account address on the .env file
  3. Update the VITE_MODULE_PUBLISHER_PRIVATE_KEY to be the existing account private key on the .env file
  4. Create or get the account you want to create a asset with, open the .env file and assign the account address as the VITE_REWARD_CREATOR_ADDRESS value.
  5. Create or get the asset you want to use in your dapp, open the .env file and assign the asset address as the VITE_FA_ADDRESS value.
  6. Finally, run npm run move:publish to publish your move module on Aptos mainnet.
  7. The next step would be to create an incentivize pool using the account you set as the VITE_REWARD_CREATOR_ADDRESS. Simply follow Incentivize the pool with rewards

API Key

  1. If you are using an API Key, make sure to update the VITE_APTOS_API_KEY with your MAINNET API Key.
  2. If you are not using an API Key, make sure to create one and update the VITE_APTOS_API_KEY with your API Key.

Deploy to a live server

create-aptos-dapp provides an npm command to easily deploy the static site to Vercel.

At the root of the folder, simply run

Then, follow the prompts. Please refer to Vercel docs to learn more about the Vercel CLI

If you are looking for different services to deploy the static site to, create-aptos-dapp utilizes Vite as the development tool, so you can follow the Vite deployment guide. In a nutshell, you would need to:

  1. Run npm run build to build a static site
  2. Run npm run preview to see how your dapp would look like on a live server
  3. Next, all you need is to deploy your static site to a live server, there are some options for you to choose from and can follow this guide on how to use each

Update the look and feel of the dapp

This template is styled with Tailwind CSS and shadcn/ui. These libraries provide the app with a neutral and clean look and feel while leaving it open to a lot of customization so that you can make the app truly yours.

Please refer to the following questions in the FAQ to learn about how to customize the UI of your dapp: