Skip to content

Java wrapper generator does not properly handle payable functions #1268

@degloff

Description

@degloff

Java wrapper generator for smart contract does not properly handle payable functions

There is no overload generated to send Ether into the smart contract function call, even though the
contract function is marked payable.

Steps To Reproduce

Consider this solidity function

    function sendEthWithContract(address payable _recipient) external payable {
        require(msg.value > 0);
        _recipient.transfer(msg.value);
    }

Compile the contract and generate the Java wrapper. It generates

    public RemoteFunctionCall<TransactionReceipt> sendEthWithContract(String _recipient) {
        final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
                FUNC_SENDETHWITHCONTRACT, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, _recipient)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

This is wrong as you have to generate an overload that passes Eth all the way down to the execution of the
transaction. This is clear as the function is marked as payable.

Instead it forwards the execution of the transaction to

    protected TransactionReceipt executeTransaction(Function function)
            throws IOException, TransactionException {
        return executeTransaction(function, BigInteger.ZERO);
    }

This is clearly wrong.

Environment

  • Web3j version. core 4.6.0, codgen 4.5.18,
  • Java 8
  • Operating System Mac OS X Catalina

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug in behaviour or functionalityneeds-reviewissue/PR needs review from maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions