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
- Object
- 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.AccessEntry | One access-list entry: an address and the storage slots the transaction will touch. |
Fields
public static final int LEGACY = 0 | The legacy envelope; signed under EIP-155 when the chain id is not zero. |
public static final int ACCESS_LIST = 1 | The EIP-2930 envelope, a legacy gas price plus an access list. |
public static final int DYNAMIC_FEE = 2 | The EIP-1559 envelope with a priority fee and a fee cap. |
Methods
Inherited methods
Field details
LEGACY
public static final int LEGACY = 0The legacy envelope; signed under EIP-155 when the chain id is not zero.
ACCESS_LIST
public static final int ACCESS_LIST = 1The EIP-2930 envelope, a legacy gas price plus an access list.
DYNAMIC_FEE
public static final int DYNAMIC_FEE = 2The 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
chainIdlong- Not documented.
noncelong- Not documented.
gasPriceUInt256- Not documented.
gasLimitlong- Not documented.
toEvmAddress- the recipient, or
nullto deploydataas a contract valueUInt256- Not documented.
databyte[]- 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
chainIdlong- Not documented.
noncelong- Not documented.
maxPriorityFeePerGasUInt256- the tip to the block producer, in wei per gas
maxFeePerGasUInt256- the most the sender pays per gas, base fee included
gasLimitlong- Not documented.
toEvmAddress- the recipient, or
nullto deploydataas a contract valueUInt256- Not documented.
databyte[]- 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()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.