Integrate Merkl to your App - Merkl API V4 Docs
Integrate Merkl in your app using Merkl API V4
Last updated
Integrate Merkl in your app using Merkl API V4
Last updated
While the offers a comprehensive interface that provides users and Liquidity Providers with everything they need to take advantage of Merkl opportunities, Merkl is also designed so anyone can integrate Merkl data into its own application and use it as a white-label solution.
This guide aims at walking you through the integration of Merkl in your app via the Merkl API.
Merkl provides an API, available that contains all the information you need to track campaigns and selectively display the ones you want on your frontend. All the data from the Merkl app is served by this API.
The documentation for can be found . We encourage you to use this documentation for reference after having read the paragraphs below.
To show Merkl data in your front-end, you have 2 types of data you can use:
Campaigns
: these are programs running on a given pool, ERC20 token, etc, over a period of time
Opportunities
: these are groups of campaigns targeting the same user base (the same pool, ERC20 token, ...). Typically, multiple campaigns can run in parallel for liquidity providers on a pool, and these all make up an opportunity.
Retrieve the Opportunity ID:
If you're a DeFi protocol integrating APRs for your own opportunities, query this API route with your protocol name:
For example, for Izumi:
Just below the tags
of an opportunity, youβll find the opportunity ID. Copy it for later.
If your opportunities are across multiple protocols, we recommend using this route:
Example: Display all campaigns associated with the Ignite Program on zkSync:
If you want a tag added to an opportunity, feel free to reach out, and we will assign the campaign to your protocolβs tag. Similarly, below tags
, youβll find the opportunity ID. Copy it for later.
Retrieve APR Data:
Once you have the opportunity ID, call the following route, replacing {id}
with your opportunity ID:
Example for SyncswapV3 USDC-wUSDM 0.3%
:
This route provides details such as APR, TVL, and daily rewards.
Here, you will find data related to this campaign start and end date, the amount of PYTH streamed, its ID, etc.
Now, you may want to display data about all the campaigns targeting this pool.
This will enable you to display aggregated data about all these campaigns.
The two routes we recommending using are:
https://api.merkl.xyz/v4/opportunities?name={protocol_name}
https://api.merkl.xyz/v4/opportunities?tags={tag}
This will give you aggregated data related to the opportunity like daily rewards, APRs, TVLs, etc.
For protocols integrating user rewards, they need to call the following API route to display the rewards earned by users:
Example: Checking a userβs rewards on zkSync:
This route provides:
Amount : the total amount of tokens to have been credited to the user onchain.
Pending : the pending rewards that will be credited onchain on the next update.
Claimed : the number of already claimed tokens.
Proofs that will assist in integrating the claiming of rewards (details in the next section).
Rewards on Merkl are claimable per token: meaning that if a user has accumulated rewards of several tokens, they may choose to only claim their rewards of one token type, just like they can choose to claim all their token rewards at once.
There are different options with which you can help your users claim their rewards:
Rely on the data provided by the Rewards
API route mentioned above (recommended): In this case the Merkl API builds entirely the claim transaction payload and the associated proof. All you need to do is call the Merkl API. This is the example shown below.
Build the proof yourself: In this setting, once the proof is built on your end, you may join it to the transaction data from the Merkl API. You can find a Github repository below showing how to do that. If you need further help, please reach out to us on Discord or Telegram.
Here is a script you may use to claim all the token rewards for a user on a chain.
Assuming you've created a campaign using $PYTH as a reward token targeting the Euler Vault 0x82D2CE1f71cbe391c05E21132811e5172d51A6EE
, you can find this campaign's data using the following endpoint: .
There are different filters available to find your campaigns. You may browse the available filters .
Taking the example from above, you may get the opportunity corresponding to the Euler vault by using: .
Once again, there are different filters available to find the opportunities of your choice. You may browse the different filters for opportunities .
The contract on which rewards should be claimed is the Distributor
contract, which address across different chains can be found on this .
Interacting safely with Merkl API is possible using our NPM package. See our guide .