跳到主要内容

receive

Contract: JBETHERC20SplitsPayer

Interface: IJBSplitsPayer

Received funds are paid to the default split group using the stored default properties.

This function is called automatically when the contract receives an ETH payment.

Definition

receive() external payable virtual override { ... }
  • The function is triggered when the contract receives ETH.
  • The function can be accessed externally by anyone.
  • The function doesn't return anything.

Body

  1. Pay the splits and get a reference to the leftover amount.

    // Pay the splits and get a reference to the amount leftover.
    uint256 _leftoverAmount = _payToSplits(
    defaultSplitsProjectId,
    defaultSplitsDomain,
    defaultSplitsGroup,
    JBTokens.ETH,
    address(this).balance,
    18, // decimals.
    defaultBeneficiary != address(0) ? defaultBeneficiary : msg.sender
    );

    Internal references:

  2. If there's no leftover amount, there's nothing left to do.

    // If there is no leftover amount, nothing left to pay.
    if (_leftoverAmount == 0) return;
  3. Pay the leftover ETH to the default project ID using the default parameters. Use the addToBalance function if there's a preference to do so. If there's no default project ID, send to the default beneficiary if there is one, otherwise send to the message sender.

    // If there's a default project ID, try to pay it.
    if (defaultProjectId != 0)
    if (defaultPreferAddToBalance)
    // Pay the project by adding to its balance if prefered.
    _addToBalanceOf(
    defaultProjectId,
    JBTokens.ETH,
    _leftoverAmount,
    18, // decimals.
    defaultMemo,
    defaultMetadata
    );
    // Otherwise, issue a payment to the project.
    else
    _pay(
    defaultProjectId,
    JBTokens.ETH,
    _leftoverAmount,
    18, // decimals.
    defaultBeneficiary != address(0) ? defaultBeneficiary : msg.sender,
    0, // min returned tokens.
    defaultPreferClaimedTokens,
    defaultMemo,
    defaultMetadata
    );
    // If no project was specified, send the funds directly to the beneficiary or the msg.sender.
    else
    Address.sendValue(
    defaultBeneficiary != address(0) ? payable(defaultBeneficiary) : payable(msg.sender),
    _leftoverAmount
    );

    Library references:

    Internal references: