Please, how to make a transaction from Brownie to a smart contract which has a receive function like so:

address payable public destination;
event ForwarderDeposited(address from, uint256 value, bytes data);

receive() external payable {
    emit ForwarderDeposited(msg.sender, msg.value, msg.data);

In, for example some test that could look like:

def test_recieve():
    # Arrange
    account = accounts[0]
    sender = accounts[1]
    # Act
    forwarder = Forwarder.deploy({"from": account})
    txn = forwarder.receive(5, {"from": sender})
    # Assert
    assert forwarder.destination().balance() == 5

Throws error: AttributeError: Contract 'Forwarder' object has no attribute 'receive'

1 Answer 1


To call your receive function from brownie, you have to use:

sender.transfer(to=forwarder, amount=5)

Also please note that you can't have msg.data with receive fallback function: see documentation here

  • Seems to be working, thanks! Just for anyone not to get confused, use like this: sender.transfer(forwarder, "1 ether")
    – ivpavici
    Mar 16, 2022 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.