AstarBase for Developers

Mario Vukelic
4 min readJul 27, 2022

--

What is AstarBase and how to use it in your project?

This article is intended for the EVM smart contract developers in Astar ecosystem.

In the recent weeks, you might have noticed ShidenPass and AstarPass launches. This means projects have enabled the mapping between Astar Native addresses and Astar EVM addresses and users have chosen to map their Native and EVM addresses. This article will show an example of how to use AstarBase mapping in your projects.

The problem AstarBase solves

Here’s the scenario: You just created a project on Astar EVM and it’s recognized by the Astar community, who choose to support your project through dApp Staking (on Astar Native). In this example, 1000 users choose to stake funds on your dApp. Now, your project is rewarded with staking income due to these 1000 loyal stakers. You want to reward those who support you through dApp staking, but you encounter a problem: How do you reward their Native addresses when you have an EVM project? They all staked with their Native (SS58) addresses and you have no idea how to identify their EVM (H160) addresses for an extra reward.

This is what AstarBase mapping solves! On Astar Network it is called AstarPass and on Shiden, ShidenPass. If your community registers on AstarPass/ShidenPass you will be able to find the SS58-H160 address pair and reward your loyal dApp stakers.

Example contract to mint reward tokens

In this example, we will create a smart contract that allows minting tokens for any Shibuya account that is staking on dApp Staking. Before going through the code there are two steps to be taken.

  1. On the Astar portal go to Shibuya (testnet) and the dApp staking tab. Pick any contract listed and stake tokens. If you do not have test tokens use the faucet to acquire them. For the staking, you will need to use wallets like Talisman or Polkadot.js extension. Remember the account you use for staking (in this article we will call it native1).
  2. Use the registration site on Shibuya to register/map your native1 account with the evm1 account.

Now that you are an active staker with account native1 mapped to your evm1, we can go through the code and claim the 10 “BestProject” ATB tokens in the example below.

Below is a simple ERC20 contract that can only be minted by an EVM account that has a registered native account pair, and that is actively staking on any contract in Dapps-staking.

To get the ABT tokens to call the claim() function and use your evm1 account for that:

If you would like to allow minting for only accounts staking on your contract, then you will use the following function call, instead.

Note! For the simplicity, this example does not prevent reuse of the same account.

FAQ

  1. How can you be sure that the paired accounts in AstarBase are not reused?
    Each native address can be used only once in AstarBase.
  2. How is account mapping done?
    A message is first signed by your native wallet account. That signed message is then sent with your EVM wallet to AstarBase contract, together with public native address. AstarBase verifies the authenticity of the signed message via SR25519 and ECDSA precompiled contract. To understand the procedure check the register() function in the AstarBase contract.
  3. Is it possible to unregister an account?
    Yes, it is possible from the backend, but the cost is set to be the same as the minimum staking amount. The reason for this cost is to prevent the reusing the same native account.
  4. Is AstarBase a verified contract and source code available?
    Yes, check the documentation for the addresses on each of the networks.
  5. Can I register even if I have used ECDSA account for staking?
    Yes, you can use ECDSA account.

For more information check AstarBase documentation.

About Astar Network

Astar Network — the Innovation Hub on Polkadot. Astar Network supports the building of dApps with EVM and WASM smart contracts and offers developers true interoperability, with cross-consensus messaging (XCM). We are made by developers and for developers. Astar’s unique Build2Earn model empowers developers to get paid through a dApp staking mechanism for the code they write and dApps they build.

Astar’s vibrant ecosystem has become Polkadot’s leading Parachain globally, supported by all major exchanges and tier 1 VCs. Astar offers the flexibility of all Ethereum and WASM toolings for developers to start building their dApps. To accelerate growth on Polkadot and Kusama Networks, Astar Space Labs offers an Incubation Hub for top TVL dApps.

Website | Twitter | Discord | Telegram | GitHub

--

--