withdrawRewards
Protocol Rewards and onchain Secondary Royalties can be withdrawn in a single transaction by executing the parameters generated from calling withdrawRewards
on the creatorClient
. The withdrawRewards
function prepares a multicall transaction that withdraws both the rewards and royalties balances for each ERC20 token associated with the specified account.
When using the Protocol SDK, any account can execute the transaction to withdraw rewards on behalf of another account. However, the rewards and royalties will always be sent to the original balance holder. This feature allows for scenarios such as a bot withdrawing rewards and covering the gas costs on behalf of the creator.
The withdrawFor
parameter specifies the account for which to withdraw the rewards. The account
parameter is set to the account that will execute the transaction.
By default, both Protocol Rewards and Secondary Royalties are withdrawn. If you wish to exclude Secondary Royalties from the withdrawal, set the claimSecondaryRoyalties
parameter to false
.
Usage
import { createCreatorClient } from "@zoralabs/protocol-sdk";
import {
creatorAccount,
chainId,
publicClient,
walletClient,
randomAccount,
} from "./config";
const creatorClient = createCreatorClient({ chainId, publicClient });
// prepare a transaction to withdraw Protocol Rewards and Secondary Royalties
const { parameters } = await creatorClient.withdrawRewards({
// account that holds the balance to withdraw for. Any outstanding eth or erc20 balance
// will be transferred to that account.
withdrawFor: creatorAccount!,
// set this to false to disable claiming secondary royalties
claimSecondaryRoyalties: true,
// account to execute the transaction. Any account can withdraw rewards for another account,
// but the the rewards will always be pulled to the account that holds the balance
account: randomAccount,
});
// simulate the transaction
const hash = await walletClient.writeContract(parameters);
// execute the transaction
const receipt = await publicClient.waitForTransactionReceipt({ hash });
if (receipt.status !== "success") {
throw new Error("transaction failed");
}
Returns
{ parameters: SimulateContractParameters }
parameters
- Type:
SimulateContractParameters
Prepared parameters for simulating/writing a transaction using viem/wagmi.
Parameters
withdrawFor
- Type:
Address
The account that holds the balance to withdraw for. Any outstanding ETH or ERC20 balance will be transferred to that account.
claimSecondaryRoyalties (optional)
- Type:
boolean
Set this to false
to disable claiming secondary royalties.
account
- Type:
Address
|Account
The account to execute the transaction. Any account can withdraw rewards for another account, but the rewards will always be sent to the account that holds the balance.