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

  1. Object
  2. 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:

ABIencode acceptsdecode answers
uintNUInt256, Long, Integer, decimal or 0x StringUInt256
intNLong, Integer, decimal StringLong up to 64 bits, decimal String above
addressEvmAddress or its StringEvmAddress
boolBooleanBoolean
bytesN, bytesbyte[]byte[]
stringStringString
arrays, tuplesList 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

signature String
name(type1,type2,...)
args Object...
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)
decode from 0x hex, the form eth_call returns.