0

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:

0x0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000bff89fe7598f162acc86cfc3267eb132f69b7e2b000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a19457468657265756d205369676e6564204d6573736167653a0a000000000000

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 ?

Thanks!

3
0

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.