Class Erc20

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

public final class Erc20 extends Object

Call data for ERC-20 tokens (USDC, USDT, DAI...). A token transfer is a transaction to the token contract with value 0 and this call data; the recipient is inside it.

EvmAddress recipient = EvmAddress.parse("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed");
EvmAddress usdc = EvmAddress.parse("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48");
long nonce = 0;
UInt256 tip = UInt256.parseUnits("1", 9);
UInt256 maxFee = UInt256.parseUnits("30", 9);
byte[] data = Erc20.transfer(recipient, UInt256.parseUnits("25", 6));  // 25 USDC
EvmTransaction tx = EvmTransaction.eip1559(1, nonce, tip, maxFee, 65000, usdc, UInt256.ZERO, data);
  • Field Details

    • TRANSFER_TOPIC

      public static final String TRANSFER_TOPIC
      Topic 0 of Transfer(address,address,uint256).
      See Also:
  • Method Details

    • transfer

      public static byte[] transfer(EvmAddress to, UInt256 amount)
      transfer(to, amount).
    • approve

      public static byte[] approve(EvmAddress spender, UInt256 amount)
      approve(spender, amount).
    • transferFrom

      public static byte[] transferFrom(EvmAddress from, EvmAddress to, UInt256 amount)
      transferFrom(from, to, amount).
    • balanceOf

      public static byte[] balanceOf(EvmAddress owner)
      balanceOf(owner), for eth_call.
    • allowance

      public static byte[] allowance(EvmAddress owner, EvmAddress spender)
      allowance(owner, spender), for eth_call.
    • decimals

      public static byte[] decimals()
      decimals(), for eth_call.
    • symbol

      public static byte[] symbol()
      symbol(), for eth_call.
    • name

      public static byte[] name()
      name(), for eth_call.
    • totalSupply

      public static byte[] totalSupply()
      totalSupply(), for eth_call.
    • decodeUint

      public static UInt256 decodeUint(byte[] returned)
      Reads a uint256 returned by balanceOf, allowance, decimals or totalSupply.
    • decodeString

      public static String decodeString(byte[] returned)
      Reads a string returned by name or symbol.
    • decodeTransfer

      public static Erc20.Transfer decodeTransfer(List<String> topics, byte[] data)

      Decodes a Transfer log from its topics and data, or answers null for any other log.

      Parameters
      • topics: the log's topics as 0x hex, as eth_getLogs returns them

      • data: the log's data