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 EvmTransaction

  1. Object
  2. EvmTransaction

An EVM transaction in any of the three envelopes nodes accept: legacy (with EIP-155 replay protection), EIP-2930 access-list (type 1) and EIP-1559 dynamic-fee (type 2).

Built, signed and serialized locally, so a node receives finished bytes and never a key:

long nonce = 0;
UInt256 tip = UInt256.parseUnits("1", 9);           // 1 gwei
UInt256 maxFee = UInt256.parseUnits("30", 9);
byte[] privateKey = SecureRandom.bytes(32);
EvmTransaction tx = EvmTransaction.eip1559(1, nonce, tip, maxFee, 21000,
        EvmAddress.parse("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"), UInt256.parseUnits("0.01", 18), null);
byte[] raw = tx.sign(privateKey).encode();   // eth_sendRawTransaction

Instances are immutable; sign and withSignature answer a signed copy, and decode reads any signed or unsigned envelope back, recovering its sender.

Nested types

class EvmTransaction.AccessEntryOne access-list entry: an address and the storage slots the transaction will touch.

Fields

public static final int LEGACY = 0The legacy envelope; signed under EIP-155 when the chain id is not zero.
public static final int ACCESS_LIST = 1The EIP-2930 envelope, a legacy gas price plus an access list.
public static final int DYNAMIC_FEE = 2The EIP-1559 envelope with a priority fee and a fee cap.

Methods

public static EvmTransaction legacy(long chainId, long nonce, UInt256 gasPrice, long gasLimit, EvmAddress to, UInt256 value, byte[] data)A legacy transaction.
public static EvmTransaction accessList(long chainId, long nonce, UInt256 gasPrice, long gasLimit, EvmAddress to, UInt256 value, byte[] data, List<EvmTransaction.AccessEntry> accessList)An EIP-2930 access-list transaction.
public static EvmTransaction eip1559(long chainId, long nonce, UInt256 maxPriorityFeePerGas, UInt256 maxFeePerGas, long gasLimit, EvmAddress to, UInt256 value, byte[] data)An EIP-1559 transaction, the default on every chain that has it.
public EvmTransaction withAccessList(List<EvmTransaction.AccessEntry> entries)This transaction with an access list (types 1 and 2 only).
public byte[] signingHash()The 32-byte Keccak hash a signer signs.
public EvmTransaction sign(byte[] privateKey)Signs with a secp256k1 private key and answers the signed transaction.
public EvmTransaction withSignature(byte[] signature65)The signed transaction, given the 65-byte r || s || recoveryId signature of signingHash that an external signer (hardware wallet, HSM) produced.
public boolean isSigned()Tells whether the transaction carries a signature.
public byte[] encode()The broadcastable bytes of a signed transaction, for eth_sendRawTransaction.
public String encodeHex()encode as 0x hex.
public byte[] hash()The transaction hash nodes and explorers know a signed transaction by.
public EvmAddress sender()The address that signed the transaction, recovered from the signature.
public UInt256 maxCost()The most this transaction can cost: value + gasLimit * (maxFeePerGas or gasPrice).
public static EvmTransaction decode(byte[] raw)Reads a transaction in any envelope, signed or as the unsigned payload a wallet is asked to sign.
public static EvmTransaction decodeHex(String hex)decode from 0x hex.
public int getType()The envelope: LEGACY, ACCESS_LIST or DYNAMIC_FEE.
public long getChainId()The chain id; 0 for a legacy transaction signed without EIP-155.
public long getNonce()The sender’s nonce.
public UInt256 getGasPrice()The gas price of a legacy or access-list transaction; null for EIP-1559.
public UInt256 getMaxPriorityFeePerGas()The EIP-1559 tip; null for the other envelopes.
public UInt256 getMaxFeePerGas()The EIP-1559 fee cap; null for the other envelopes.
public long getGasLimit()The gas limit.
public EvmAddress getTo()The recipient, or null for a contract deployment.
public UInt256 getValue()The value sent, in wei.
public byte[] getData()A copy of the call data.
public List<EvmTransaction.AccessEntry> getAccessList()The access list, empty for a legacy transaction.
public byte[] getSignature()The 65-byte r || s || recoveryId signature, or null when unsigned.

Inherited methods

Field details

LEGACY

public static final int LEGACY = 0
The legacy envelope; signed under EIP-155 when the chain id is not zero.

ACCESS_LIST

public static final int ACCESS_LIST = 1
The EIP-2930 envelope, a legacy gas price plus an access list.

DYNAMIC_FEE

public static final int DYNAMIC_FEE = 2
The EIP-1559 envelope with a priority fee and a fee cap.

Method details

legacy

public static EvmTransaction legacy(long chainId, long nonce, UInt256 gasPrice, long gasLimit, EvmAddress to, UInt256 value, byte[] data)
A legacy transaction. A chainId of 0 signs without EIP-155 replay protection, which nodes increasingly refuse; pass the real chain id.

Parameters

chainId long
Not documented.
nonce long
Not documented.
gasPrice UInt256
Not documented.
gasLimit long
Not documented.
to EvmAddress
the recipient, or null to deploy data as a contract
value UInt256
Not documented.
data byte[]
Not documented.

accessList

public static EvmTransaction accessList(long chainId, long nonce, UInt256 gasPrice, long gasLimit, EvmAddress to, UInt256 value, byte[] data, List<EvmTransaction.AccessEntry> accessList)
An EIP-2930 access-list transaction.

eip1559

public static EvmTransaction eip1559(long chainId, long nonce, UInt256 maxPriorityFeePerGas, UInt256 maxFeePerGas, long gasLimit, EvmAddress to, UInt256 value, byte[] data)
An EIP-1559 transaction, the default on every chain that has it.

Parameters

chainId long
Not documented.
nonce long
Not documented.
maxPriorityFeePerGas UInt256
the tip to the block producer, in wei per gas
maxFeePerGas UInt256
the most the sender pays per gas, base fee included
gasLimit long
Not documented.
to EvmAddress
the recipient, or null to deploy data as a contract
value UInt256
Not documented.
data byte[]
Not documented.

withAccessList

public EvmTransaction withAccessList(List<EvmTransaction.AccessEntry> entries)
This transaction with an access list (types 1 and 2 only).

signingHash

public byte[] signingHash()
The 32-byte Keccak hash a signer signs.

sign

public EvmTransaction sign(byte[] privateKey)
Signs with a secp256k1 private key and answers the signed transaction.

withSignature

public EvmTransaction withSignature(byte[] signature65)
The signed transaction, given the 65-byte r || s || recoveryId signature of signingHash that an external signer (hardware wallet, HSM) produced.

isSigned

public boolean isSigned()
Tells whether the transaction carries a signature.

encode

public byte[] encode()
The broadcastable bytes of a signed transaction, for eth_sendRawTransaction.

encodeHex

public String encodeHex()
encode as 0x hex.

hash

public byte[] hash()
The transaction hash nodes and explorers know a signed transaction by.

sender

public EvmAddress sender()
The address that signed the transaction, recovered from the signature.

Throws

IllegalStateException
when unsigned
com.codename1.security.CryptoException
when the signature recovers no key

maxCost

public UInt256 maxCost()
The most this transaction can cost: value + gasLimit * (maxFeePerGas or gasPrice).

decode

public static EvmTransaction decode(byte[] raw)
Reads a transaction in any envelope, signed or as the unsigned payload a wallet is asked to sign.

Throws

IllegalArgumentException
for malformed or non-canonical bytes, or an envelope other than 0, 1 and 2

decodeHex

public static EvmTransaction decodeHex(String hex)
decode from 0x hex.

getType

public int getType()
The envelope: LEGACY, ACCESS_LIST or DYNAMIC_FEE.

getChainId

public long getChainId()
The chain id; 0 for a legacy transaction signed without EIP-155.

getNonce

public long getNonce()
The sender’s nonce.

getGasPrice

public UInt256 getGasPrice()
The gas price of a legacy or access-list transaction; null for EIP-1559.

getMaxPriorityFeePerGas

public UInt256 getMaxPriorityFeePerGas()
The EIP-1559 tip; null for the other envelopes.

getMaxFeePerGas

public UInt256 getMaxFeePerGas()
The EIP-1559 fee cap; null for the other envelopes.

getGasLimit

public long getGasLimit()
The gas limit.

getTo

public EvmAddress getTo()
The recipient, or null for a contract deployment.

getValue

public UInt256 getValue()
The value sent, in wei.

getData

public byte[] getData()
A copy of the call data.

getAccessList

public List<EvmTransaction.AccessEntry> getAccessList()
The access list, empty for a legacy transaction.

getSignature

public byte[] getSignature()
The 65-byte r || s || recoveryId signature, or null when unsigned.