Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class Abi
- Object
- Abi
The Solidity contract ABI: function selectors, call data and return values.
EvmAddress recipient = EvmAddress.parse("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed");
UInt256 amount = UInt256.parseUnits("25", 6);
byte[] data = Abi.encodeCall("transfer(address,uint256)", recipient, amount);
byte[] returned = new byte[32]; // what eth_call answered
List<Object> out = Abi.decode("(uint256)", returned); // [UInt256]
Types are written as in a Solidity signature: uint8..uint256, int8..int256,
address, bool, bytes1..bytes32, bytes, string, arrays T[] and T[k], and
tuples (T1,T2). Values map to Java as:
| ABI | encode accepts | decode answers |
|---|---|---|
uintN | UInt256, Long, Integer, decimal or 0x String | UInt256 |
intN | Long, Integer, decimal String | Long up to 64 bits, decimal String above |
address | EvmAddress or its String | EvmAddress |
bool | Boolean | Boolean |
bytesN, bytes | byte[] | byte[] |
string | String | String |
| arrays, tuples | List or Object[] | List<Object> |
Methods
public static byte[] selector(String signature) | The 4-byte selector of a function signature such as transfer(address,uint256). |
public static byte[] eventTopic(String signature) | The topic 0 of an event signature such as Transfer(address,address,uint256). |
public static byte[] encodeCall(String signature, Object... args) | The call data for a function: its selector followed by the encoded arguments. |
public static byte[] encode(String tupleType, Object... values) | Encodes values against a tuple type such as (address,uint256[],string). |
public static List<Object> decode(String tupleType, byte[] data) | Decodes ABI bytes against a tuple type, answering one value per member. |
public static List<Object> decodeHex(String tupleType, String hex) | decode from 0x hex, the form eth_call returns. |
Inherited methods
Method details
selector
public static byte[] selector(String signature)The 4-byte selector of a function signature such as
transfer(address,uint256).eventTopic
public static byte[] eventTopic(String signature)The topic 0 of an event signature such as
Transfer(address,address,uint256).encodeCall
public static byte[] encodeCall(String signature, Object... args)The call data for a function: its selector followed by the encoded arguments.
Parameters
signatureStringname(type1,type2,...)argsObject...- one value per parameter
encode
public static byte[] encode(String tupleType, Object... values)Encodes values against a tuple type such as
(address,uint256[],string).decode
public static List<Object> decode(String tupleType, byte[] data)Decodes ABI bytes against a tuple type, answering one value per member.
decodeHex
public static List<Object> decodeHex(String tupleType, String hex)