Class Abi

java.lang.Object
com.codename1.crypto.evm.Abi

public final class Abi extends Object

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>
  • 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: name(type1,type2,...)

      • args: 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(String, byte[]) from 0x hex, the form eth_call returns.