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 Erc20

  1. Object
  2. Erc20

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);

Nested types

class Erc20.TransferA decoded Transfer event.

Fields

public static final String TRANSFER_TOPIC = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"Topic 0 of Transfer(address,address,uint256).

Methods

public static byte[] transfer(EvmAddress to, UInt256 amount)transfer(to, amount).
public static byte[] approve(EvmAddress spender, UInt256 amount)approve(spender, amount).
public static byte[] transferFrom(EvmAddress from, EvmAddress to, UInt256 amount)transferFrom(from, to, amount).
public static byte[] balanceOf(EvmAddress owner)balanceOf(owner), for eth_call.
public static byte[] allowance(EvmAddress owner, EvmAddress spender)allowance(owner, spender), for eth_call.
public static byte[] decimals()decimals(), for eth_call.
public static byte[] symbol()symbol(), for eth_call.
public static byte[] name()name(), for eth_call.
public static byte[] totalSupply()totalSupply(), for eth_call.
public static UInt256 decodeUint(byte[] returned)Reads a uint256 returned by balanceOf, allowance, decimals or totalSupply.
public static String decodeString(byte[] returned)Reads a string returned by name or symbol.
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.

Inherited methods

Field details

TRANSFER_TOPIC

public static final String TRANSFER_TOPIC = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
Topic 0 of Transfer(address,address,uint256).

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 List<String>
the log’s topics as 0x hex, as eth_getLogs returns them
data byte[]
the log’s data