Claiming Rewards
In this guide, you’ll learn how to help your customers claim their rewards from Fee Pool.
To collect rewards for a wallet, your customer needs to call the collectReward
method from the Fee Pool smart contract.
How to Call the Smart Contract?
To claim rewards, you’ll need to create a Web UI that enables your customers to connect their wallet and call the Fee Pool smart contract. Only the customer can claim their rewards using this method.
Example (using viem
library):
import { createWalletClient, custom, http } from 'viem'
import { holesky } from 'viem/chains'
export const publicClient = createPublicClient({
chain: holesky,
transport: http()
})
export const walletClient = createWalletClient({
chain: holesky,
transport: custom(window.ethereum)
})
export const [account] = await walletClient.getAddresses()
const FEE_POOL_ADDRESS = "0xe876FF5DAe83cd04484Dd7d590b06E28Ac31F248"
const CLAIM_AMOUNT = 10000000 // wei
const { request } = await publicClient.simulateContract({
account,
address: FEE_POOL_ADDRESS,
abi: [
{
"inputs": [
{
"internalType": "address payable",
"name": "beneficiary",
"type": "address"
},
{
"internalType": "uint256",
"name": "amountRequested",
"type": "uint256"
}
],
"name": "collectReward",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
],
functionName: 'collectReward',
args: [account, CLAIM_AMOUNT]
})
await walletClient.writeContract(request)
console.log("request", request)
Fee Pool Smart Contract
Here you can find interface of the collectReward
method in Solidity:
/**
* @notice Allows a depositor (`msg.sender`) to collect their rewards from the pool.
* @dev Emits a {ValidatorRewardCollected} event.
* Requirements:
* - The pool must be open for withdrawals (Pool is not currently open for withdrawal).
* - `amountRequested` cannot exceed the available balance (Not enough pending rewards).
* @param beneficiary The address that will receive the `amountRequested`. If not set, it defaults to `msg.sender`.
* @param amountRequested The amount to send to the `beneficiary`. If 0, all pending rewards are sent.
*/
function collectReward(address payable beneficiary, uint256 amountRequested) external;
Claiming Wallet Rewards on Etherscan
If you'd prefer not to write code to claim rewards, you can easily do so using Etherscan. Here’s a step-by-step guide using stakefish's fee pool on Holesky.
Step 1: Open the Contract on Etherscan
Navigate to the contract on Etherscan and select the Contract tab. Then, click on Write as Proxy to access the contract's write methods. Next, click Connect to Web3 to enable interaction with the contract.
Step 2: Connect Your Wallet
You’ll be prompted to connect your Web3 wallet. Follow the Etherscan instructions to connect your wallet. Once connected, the Connect to Web3 button will turn green and display Connected - Web3 [your wallet address].
Step 3: Use the collectReward
Method
In the list of contract methods, locate the collectReward
function. Input the beneficiary address (this can be your wallet address or another recipient), enter the amount you want to claim (in wei), and click Write.
If you want to claim all rewards, you can set the amount to 0
.
Step 4: Confirm the Transaction in Your Wallet
Once you click Write, you’ll need to confirm the transaction in your wallet. Follow the prompts to authorize the transaction.
Step 5: Check the Status of Your Transaction
After submitting the transaction, you can monitor its status by clicking View your transaction.
This will take you to the transaction page on Etherscan, where you can see if the transaction has been successfully mined.
Once your transaction is successful, the rewards will be transferred to the specified beneficiary address.
Updated 2 months ago