# Receive Referral Reward

Trader can claim their referral reward via ReferralRewarder contract for each chain.

## Contract address

```
BNB chain: 0xCEaBce51c59d44C8dE3E58599c296787A9523Fc7

Arbitrum One: 0x2100Ed94172b0627D6fe772EB11B16d9Ba1C4CeA
```

{% hint style="info" %}
**Note**: Please use the contract on the exact chain you set to claim reward before
{% endhint %}

![image](https://user-images.githubusercontent.com/111835274/254763172-962fdff0-7d33-4d93-809f-5095ff807cb8.png)

### Step 1: Get claimable reward

* Get the reward information via this method

```
function epoches() external view 
    returns (
        bytes32 merkleRoot,
        bytes32 ipfsHash,
        uint256 totalRewards,
        uint256 totalClaimed,
        uint64 startVestingTime,
        uint64 endVestingTime
    );
```

The `ipfsHash` is decoded IPFS CID of the airdrop detail file. You will need to encode to get the original CID, like this

```
const hex = '1220' + ipfs.slice(2); // remove '0x' prefix and prepend 1220 tag for v2 CID
bs58.encode(Buffer.from(hash, 'hex'))
```

**Eg:**

```
bs58.encode(Buffer.from('1220f6e849cffef302146a84e8d4e41c072410ea214dba9cc05a44af0f302c713a1b', 'hex'));

// result: QmexUSUxsUvDzfns9GUoMw19Gqoj885v6H85XMxu68EpVG
```

Then use any IPFS gateway to get file content, like [this](https://cloudflare-ipfs.com/ipfs/QmexUSUxsUvDzfns9GUoMw19Gqoj885v6H85XMxu68EpVG). It is a JSON file with some data. Find your address in the file, something like this

```
{
    "id": 0,
    "address": "0xd93497c4659276569f49a32a7abd0691f5ac4467",
    "rewards_amount": "53872166745238961245",
    "rewards_claim_on": 56,
    "rewards_value": "183046130390007773813415143771401",
    "ref_tier": 0,
    "ref_count": 7,
    "ref_point": "0",
    "ref_rebate_value": "0",
    "ref_rebate_amount": "0",
    "trader_ref_tier": 1,
    "trader_ref_to": "0xebc175b5e5323ceae881ed165fee6f7164a912da",
    "trader_point": "3660922607800155476268302875428039",
    "trader_discount_value": "183046130390007773813415143771401",
    "trader_discount_amount": "53872166745238961245",
    "trading_fee": [
      {
        "chain_id": 56,
        "value": "319913282924852490765592624530694"
      },
      {
        "chain_id": 42161,
        "value": "3341009324875302985502710250897345"
      }
    ],
    "proof": [
      "0xad4dc10f2e49513d0ce7d8f70eccd344100f1f504f0dc970bcbef9b7ce51fda2",
      "0x55936a5d804758498e334ceb13eace213f21adccb971f84431f93ad08460b08b",
      "0xe476b39cd5a8ff311c7bb2b01834395a308bdaaf3d420a995e0a3fb94193ede0",
      "0xd1d5a68fff109730859fb298bca5b1c5b2786c6d04e59fb6ea087910eaad7252",
      "0xd2731f8bb49a5bea6163b7cb49a9c6ae11c60ae15ddd03a8a3c1ff7c21362ab1",
      "0xed3046df03a6849286b962681dbef58d43672f6e26af68c33abad847594e3a13"
    ]
}
```

Save the value of the fields `id` and `proof` to claim your reward

### Step 2: Claim reward

Use this method from the `ReferralRewarder` contract to claim your reward.

```
function claimRewards(uint256 _epoch, address _to, uint256 _index, uint256 _rewards, bytes32[] memory _merkleProof);
```

* \_epoch: The epoch number
* \_to: The address to which reward will be sent
* \_index: the `id` value in step 1
* \_merkleProof: the `proof` value in step 1

Now the reward should be sent to the address you set.
