The Broadcaster network, forward private transactions on behalf of users and covering the associated gas costs. Users pay a small premium on top of the gas cost from their private balance to the Broadcaster's private balance in exchange for the service.
Broadcasters are only needed for transactions that originate from a 0zk address (i.e. not needed for Shield transactions). Through Broadcaster, private transactions within the RAILGUN privacy system remain unlinked to public addresses, ensuring anonymity even during interactions with smart contracts.
Broadcasters broadcast their fees and accept transactions via the Waku Network (as opposed to using HTTP requests) so that nobody can snoop on a user's IP address when submitting a transaction.
The initialized RailgunWakuBroadcasterClient will continue monitoring the connection to the Broadcaster network throughout the app session. It will call the statusCallback function with updates, and you must wait to use a Broadcaster until the status is Connected.
Finding a Broadcaster
When you are connected to the Broadcaster network and you are ready to submit a private transaction, you must first select a token from the user's private balance to pay the Broadcaster fee (likely from user input).
Next, we need to find the best Broadcaster based on the user's selected fee token and the fee amounts that the Broadcasters are broadcasting.
If no Broadcaster is available that accepts fees in the selected token, then the findBestBroadcaster function will return undefined.
Calculating the Broadcaster Fee
Once we have a SelectedBroadcaster, we need to calculate the total Broadcaster fee for our transaction based on the current gas price, gas estimate of the transaction, and the fee that the Broadcaster charges.
import {
RailgunPopulateTransactionResponse
} from '@railgun-community/shared-models';
const populateResponse: RailgunPopulateTransactionResponse = ...; // See the examples in the "Transactions" section for getting this value
const overallBatchMinGasPrice: bigint = ...; // See the examples in the "Transactions" section for getting this value
const selectedBroadcaster = ...; // Same as examples above
const chain: Chain = ...; // Same as examples above
const useRelayAdapt = ...; // Same as examples above
const nullifiers: string[] = populateResponse.nullifiers ?? [];
const broadcasterTransaction = await BroadcasterTransaction.create(
populateResponse.transaction.to,
populateResponse.transaction.data,
selectedBroadcaster.railgunAddress,
selectedBroadcaster.tokenFee.feesID,
chain,
nullifiers,
overallBatchMinGasPrice,
useRelayAdapt,
);
const txHash = await broadcasterTransaction.send();