> ## Documentation Index
> Fetch the complete documentation index at: https://docs.boost.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Claim Rewards from a Boost

> Learn how to claim rewards from a Boost

In this example, you'll learn how to claim a reward from a Boost.

To claim a reward from a Boost, you'll need to follow these general steps:

1. Retrieve the Boost you want to claim from
2. Prepare the claim data payload
3. Execute the claim transaction

This process will differ depending on if you have set up your own validator or are using the default validator.
If using the default validator, you will need to call the [Boost API `/signatures` endpoint](/v2/boost-api/get-signature) to generate the signature payload,
otherwise you will need to build the payload yourself.

<Tip>
  The default validator will be always be used by default unless you specify your own validator on boost creation.
</Tip>

<Tabs>
  <Tab title="Using the Default Validator">
    In order to claim an incentive from a boost using the default validator, you will need to generate a valid signature payload.
    You can do this by calling the boost api `/signatures` endpoint and passing in the boostID and txHash.

    <Note>
      You can also generate a signature by providing a wallet address instead of a transaction hash using the `/transactions` endpoint.
      See [Fetching Signature by Address](/v2/boost-api/get-signature#fetching-signature-by-address) for details.
    </Note>

    This example assumes you have already instantiated a `BoostCore` client and have a valid transaction hash for the action that the claimant completed.

    <Card title="Claim Signature API" icon="signature" href="/v2/api-reference/boost/generate-a-claim-signature-that-can-be-used-to-submit-a-claim">
      See additional documentation on how to build a claim signature
    </Card>

    ### Generate the Signature Payload

    ```ts theme={null}
    import axios from 'axios';

    const chainId = 8453; // base mainnet
    const boost = await core.getBoost(3n, { chainId })
    const boostCoreAddress = core.assertValidAddress()

    const { data } = await axios.get(`${BOOST_API_URL}/signatures`, {
      params: {
        boostId: `${chainId}:${boostCoreAddress}:${boost.id}`,
        txHash,
      }
    });
    ```

    The `/signatures` endpoint will return an array of signatures, one for each available incentive on the boost.
    Each item in the array will contain the following fields:

    * `signature`: The signature to be used in the claim transaction
    * `incentiveId`: The id of the incentive being claimed
    * `claimant`: The address of the claimant

    If using `ERC20VariableIncentive` or `ERC20VariableCriteriaIncentive`, you will need to pass in the `rewardAmount` as `claimData` to the `/signatures` endpoint.

    Here's an example of how you would accomplish that with multiple incentives.

    ```ts theme={null}
    const allClaimData = boost.incentives.map(incentive => {
      if (incentive instanceof ERC20VariableIncentive || incentive instanceof ERC20VariableCriteriaIncentive) {
        const rewardAmount = parseUnits("10", 18);
        return incentive.buildClaimData(rewardAmount);
      } else {
        return ''
      }
    })

    const { data } = await axios.get(`${BOOST_API_URL}/signatures`, {
      params: {
        boostId: `${chainId}:${boostCoreAddress}:${boost.id}`,
        txHash,
        claimData: allClaimData.join(',')
      }
    });
    ```

    ### Claiming the incentives

    Once you have a valid response from the `/signatures` endpoint, you can loop through the response and claim the incentives.

    ```ts index.ts {13-22} theme={null}
    import axios from 'axios';

    const chainId = 8453; // base mainnet
    const boost = await core.getBoost(3n, { chainId })
    const boostCoreAddress = core.assertValidAddress()

    const { data } = await axios.get(`${BOOST_API_URL}/signatures`, {
      params: {
        boostId: `${chainId}:${boostCoreAddress}:${boost.id}`,
        txHash,
      }
    });

    for (const item of data) {
      const { signature, incentiveId, claimant } = item;

      // Allow the claimant to claim the incentive
      await core.claimIncentive(
        boost.id,
        incentiveId,
        claimant,
        signature,
      );
    }
    ```

    <Warning>
      `claimIncentive` must be called by the claimant. This is useful if you have access to the claimants wallet, like in the case of a dapp.
      If you are claiming on behalf of another user, you must use `claimIncentiveFor`.
    </Warning>

    You can also claim on behalf of another user by using the `claimIncentiveFor` method.

    ```ts theme={null}
    // Claim on behalf of another user
    await core.claimIncentiveFor(
      boost.id,
      incentiveId, // the incentiveId (position in the array of incentives)
      "0xREFERRER", // referrer (if any). use zero address if no referrer
      signature,
      claimant, // the address of the account the claim is being made for
    );
    ```
  </Tab>

  <Tab title="Using Your Own Validator">
    [//]: # "TODO: link to validator page when it's published to provde more context"

    [//]: # "TODO: show how to validate actions without using the api"

    ```ts theme={null}
    // get the boost you want to claim from
    const boost = await core.getBoost(1n)

    // get an incentive from the boost
    const incentiveId = 0n; // the position in the incentives array
    const incentive = boost.incentives[incentiveId]

    // prepare the incentive payload
    let incentivePayload: Hex;

    // variable reward incentives require the reward amount to be provided in buildClaimData
    if (incentive instanceof ERC20VariableIncentive ||
        incentive instanceof ERC20VariableCriteriaIncentive) {
      const rewardAmount = parseUnits("10", 18);
      incentivePayload = incentive.buildClaimData(rewardAmount);
    } else {
      incentivePayload = incentive.buildClaimData();
    }

    // encode claimData payload
    const claimDataPayload = await boost.validator.encodeClaimData({
      signer: signer.account,
      incentiveData: incentivePayload,
      chainId: 8453,
      incentiveQuantity: 1,
      claimant: "0xCLAIMANT", // the address of the account claiming the incentive
      boostId: boost.id,
    });

    // claim the incentive from the boost
    await core.claimIncentive(
      boost.id,
      incentiveId, // the incentiveId (position in the array of incentives)
      "0xCLAIMANT", // the claimant
      claimDataPayload,
    );
    ```

    <Warning>
      The claimant must be authorized to claim the incentive (e.g., on allowlist)
    </Warning>

    You can also claim on behalf of another user by using the `claimIncentiveFor` method.

    ```ts theme={null}
    await core.claimIncentiveFor(
      boost.id,
      0n, // the incentiveId (position in the array of incentives)
      "0xREFERRER", // referrer (if any). use zero address if no referrer
      claimDataPayload,
      "0xCLAIMANT", // the address of the account the claim is being made for
    );
    ```
  </Tab>
</Tabs>
