Class 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(byte[]) and withSignature(byte[]) answer a signed copy, and
decode(byte[]) reads any signed or unsigned envelope back, recovering its sender().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOne access-list entry: an address and the storage slots the transaction will touch. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe EIP-2930 envelope, a legacy gas price plus an access list.static final intThe EIP-1559 envelope with a priority fee and a fee cap.static final intThe legacy envelope; signed under EIP-155 when the chain id is not zero. -
Method Summary
Modifier and TypeMethodDescriptionstatic EvmTransactionaccessList(long chainId, long nonce, UInt256 gasPrice, long gasLimit, EvmAddress to, UInt256 value, byte[] data, List<EvmTransaction.AccessEntry> accessList) An EIP-2930 access-list transaction.static EvmTransactiondecode(byte[] raw) Reads a transaction in any envelope, signed or as the unsigned payload a wallet is asked to sign.static EvmTransactiondecode(byte[])from0xhex.static EvmTransactioneip1559(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.byte[]encode()The broadcastable bytes of a signed transaction, foreth_sendRawTransaction.encode()as0xhex.The access list, empty for a legacy transaction.longThe chain id; 0 for a legacy transaction signed without EIP-155.byte[]getData()A copy of the call data.longThe gas limit.The gas price of a legacy or access-list transaction;nullfor EIP-1559.The EIP-1559 fee cap;nullfor the other envelopes.The EIP-1559 tip;nullfor the other envelopes.longgetNonce()The sender's nonce.byte[]The 65-byter || s || recoveryIdsignature, ornullwhen unsigned.getTo()The recipient, ornullfor a contract deployment.intgetType()getValue()The value sent, in wei.byte[]hash()The transaction hash nodes and explorers know a signed transaction by.booleanisSigned()Tells whether the transaction carries a signature.static EvmTransactionlegacy(long chainId, long nonce, UInt256 gasPrice, long gasLimit, EvmAddress to, UInt256 value, byte[] data) A legacy transaction.maxCost()The most this transaction can cost:value + gasLimit * (maxFeePerGas or gasPrice).sender()The address that signed the transaction, recovered from the signature.sign(byte[] privateKey) Signs with a secp256k1 private key and answers the signed transaction.byte[]The 32-byte Keccak hash a signer signs.withAccessList(List<EvmTransaction.AccessEntry> entries) This transaction with an access list (types 1 and 2 only).withSignature(byte[] signature65) The signed transaction, given the 65-byter || s || recoveryIdsignature ofsigningHash()that an external signer (hardware wallet, HSM) produced.
-
Field Details
-
LEGACY
public static final int LEGACYThe legacy envelope; signed under EIP-155 when the chain id is not zero.- See Also:
-
ACCESS_LIST
public static final int ACCESS_LISTThe EIP-2930 envelope, a legacy gas price plus an access list.- See Also:
-
DYNAMIC_FEE
public static final int DYNAMIC_FEEThe EIP-1559 envelope with a priority fee and a fee cap.- See Also:
-
-
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
chainIdof 0 signs without EIP-155 replay protection, which nodes increasingly refuse; pass the real chain id.Parameters
to: the recipient, ornullto deploydataas a contract
-
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
-
maxPriorityFeePerGas: the tip to the block producer, in wei per gas -
maxFeePerGas: the most the sender pays per gas, base fee included -
to: the recipient, ornullto deploydataas a contract
-
-
withAccessList
This transaction with an access list (types 1 and 2 only). -
signingHash
public byte[] signingHash()The 32-byte Keccak hash a signer signs. -
sign
Signs with a secp256k1 private key and answers the signed transaction. -
withSignature
The signed transaction, given the 65-byter || s || recoveryIdsignature ofsigningHash()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, foreth_sendRawTransaction. -
encodeHex
-
hash
public byte[] hash()The transaction hash nodes and explorers know a signed transaction by. -
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
The most this transaction can cost:value + gasLimit * (maxFeePerGas or gasPrice). -
decode
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
decode(byte[])from0xhex. -
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
The gas price of a legacy or access-list transaction;nullfor EIP-1559. -
getMaxPriorityFeePerGas
The EIP-1559 tip;nullfor the other envelopes. -
getMaxFeePerGas
The EIP-1559 fee cap;nullfor the other envelopes. -
getGasLimit
public long getGasLimit()The gas limit. -
getTo
The recipient, ornullfor a contract deployment. -
getValue
The value sent, in wei. -
getData
public byte[] getData()A copy of the call data. -
getAccessList
The access list, empty for a legacy transaction. -
getSignature
public byte[] getSignature()The 65-byter || s || recoveryIdsignature, ornullwhen unsigned.
-