let say we have the following function in solidity:

function tryAbiEncode (address  _address, uint8 _amount) public pure returns (bytes memory)
    return abi.encode("\x19Ethereum Signed Message:\n",_address, _amount);

If I executed the above function with the following parameters:

_address = 0xbfF89Fe7598f162ACC86CfC3267Eb132F69B7e2B
_amount = 10

I will get the below result:


My question is, how I can get the same results but in Java using web3j library ? I mean how I can execute abi.encode but in Java ?



Web3j does not provide such methods. However, you can tinker with the internal types to get what you're looking for.

A good place to start is the ABI tests.

You should define a Function with the parameters you specified. Then, you can encode it the same way we are doing in most tests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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