Skip to content

getRewardsBalances

The getRewardsBalances function on the creatorClient allows you to view the rewards and royalties balances for any account. This function returns two types of balances:

  1. Protocol Rewards: The total rewards balance from primary sales, stored in the Protocol Rewards contract.
  2. Royalties: The total royalties earned from onchain secondary sales. The royalties balances are aggregated by ERC20 token and also include the sum for ETH. This provides a comprehensive view of an account's earnings from both primary and secondary sales.

Usage

example.ts
import { useAccount, useChainId, usePublicClient } from "wagmi";
import { createCreatorClient } from "@zoralabs/protocol-sdk";
 
// use wagmi hooks to get the chainId, publicClient, and account
const chainId = useChainId();
const publicClient = usePublicClient()!;
const { address } = useAccount();
 
const creatorClient = createCreatorClient({ chainId, publicClient });
 
// get the rewards balance for the given account
const rewardsBalance = await creatorClient.getRewardsBalances({
  account: address!,
});
 
// get the protocol rewards balance of the account in ETH
const protocolRewardsBalance = rewardsBalance.protocolRewards;
// get the secondary roylaties balance in ETH
const secondaryRoyaltiesBalanceEth = rewardsBalance.secondaryRoyalties.eth;
// get the secondary royalties balance for an erc20 token
const secondaryRoyaltiesBalancesByErc20 =
  rewardsBalance.secondaryRoyalties.erc20;
 
console.log({
  protocolRewardsBalance,
  secondaryRoyaltiesBalanceEth,
  secondaryRoyaltiesBalancesByErc20,
});

Returns

{ protocolRewards: bigint, royalties: Record<string, bigint> }

protocolRewards

  • Type: bigint

The total rewards balance from the Protocol Rewards contract.

royalties

  • Type: Record<string, bigint>

The total royalties balances from secondary sales, aggregated by ERC20 token and summed up for eth.

Parameters

account

  • Type: Address | Account

The account to get the rewards balances for.