Objects

Objects used within ledgereth.

class ledgereth.objects.ISO7816Command(CLA: bytes, INS: bytes, P1: bytes, P2: bytes, Lc: Optional[bytes] = None, Le: Optional[bytes] = None, data: Optional[bytes] = None)[source]

A representation of an ISO-7816 APDU Command binary to be sent to the Ledger device.

encode() bytes[source]

Encode the command into bytes to be sent to the Ledger device.

Returns

Encoded bytes data

encode_hex() str[source]

Encode the command into hex bytes representation.

Returns

Encoded hex str

set_data(data: bytes, Lc: Optional[bytes] = None) None[source]

Set the command data and its length

Parameters
  • data – (bytes) - The raw bytes data. This should not exceed the max chunk length of 255 (including command data)

  • Lc – (bytes) - The length of the data

class ledgereth.objects.LedgerAccount(path, address)[source]

A representation of an account derived from the private key on a Ledger device.

__init__(path, address)[source]

Initialize an account.

Parameters
  • path – (str) Derivation path for the account

  • address – (str) Address of the account

address: str

The account’s address

path: str

The HD path of the account

path_encoded: bytes

The HD path of the account

class ledgereth.objects.SerializableTransaction(*args, **kwargs)[source]

An RLP Serializable transaction object

abstract classmethod from_rawtx(rawtx: bytes) ledgereth.objects.SerializableTransaction[source]

Instantiates a SerializableTransaction given a raw encoded transaction

Parameters

rawtx – (bytes) - The decoded raw transaction bytes to encode into a ledgereth.objects.SerializableTransaction

Returns

Instantiated ledgereth.objects.SerializableTransaction

to_dict() Dict[str, Any][source]

Return a dictionary representation of the transaction

Returns

Transaction dict

to_rpc_dict() Dict[str, Any][source]

To a dict compatible with web3.py or JSON-RPC

Returns

Transaction dict

class ledgereth.objects.Signed(v, r, s)[source]
r: int

Signature r

s: int

Signature s

property signature

Encoded signature

Returns

Signature bytes

v: int

Signature v

class ledgereth.objects.SignedMessage(message, v, r, s)[source]

Signed EIP-191 message

__init__(message, v, r, s)[source]

Initialize a singed message

Parameters
  • message – (bytes) Message that was signed

  • v – (int) Signature v value

  • r – (int) Signature r value

  • s – (int) Signature s value

class ledgereth.objects.SignedTransaction(nonce: int, gas_price: int, gas_limit: int, destination: bytes, amount: int, data: bytes, v: int, r: int, s: int)[source]

Signed legacy or EIP-155 transaction

__init__(nonce: int, gas_price: int, gas_limit: int, destination: bytes, amount: int, data: bytes, v: int, r: int, s: int)[source]

Initialize an unsigned transaction

Parameters
  • nonce – (int) Transaction nonce

  • gas_price – (int) Gas price in wei

  • gas_limit – (int) Gas limit

  • destination – (bytes) Destination address

  • amount – (int) Amount of Ether to send in wei

  • data – (bytes) Transaction data

  • v – (int) Signature v value

  • r – (int) Signature r value

  • s – (int) Signature s value

classmethod from_rawtx(rawtx: bytes) ledgereth.objects.SignedTransaction[source]

Instantiate a SignedTransaction object from a raw encoded transaction

Parameters

rawtx – (bytes) A raw signed transaction to instantiate with

Returns

ledgereth.objects.SignedTransaction

property rawTransaction

Encoded raw signed transaction

raw_transaction()[source]

Return an encoded raw signed transaction

Encoded signed TX format spec:

rlp([nonce, gasPrice, gasLimit, destination, amount, data, signatureV, signatureR, signatureS])
Returns

Encoded raw signed transaction bytes

transaction_type = 0

The EIP-2718 transaction type

class ledgereth.objects.SignedType1Transaction(chain_id: int, nonce: int, gas_price: int, gas_limit: int, destination: bytes, amount: int, data: bytes, access_list: List[Tuple[bytes, List[int]]], y_parity: int, sender_r: int, sender_s: int)[source]

A signed Type 1 transaction.

__init__(chain_id: int, nonce: int, gas_price: int, gas_limit: int, destination: bytes, amount: int, data: bytes, access_list: List[Tuple[bytes, List[int]]], y_parity: int, sender_r: int, sender_s: int)[source]

Initialize a signed type 1 transaction

Parameters
  • chain_id – (int) Chain ID

  • nonce – (int) Transaction nonce

  • gas_price – (int) Gas price in wei

  • gas_limit – (int) Gas limit

  • destination – (bytes) Destination address

  • amount – (int) Amount of Ether to send in wei

  • data – (bytes) Transaction data

  • access_list – (List[Tuple[bytes, List[int]]]) EIP-2718 Access list

  • y_parity – (int) Parity byte for the signature

  • sender_r – (int) Signature r value

  • sender_s – (int) Signature s value

classmethod from_rawtx(rawtx: bytes) ledgereth.objects.SignedType1Transaction[source]

Instantiate a SignedType1Transaction object from a raw encoded transaction

Parameters

rawtx – (bytes) A raw signed transaction to instantiate with

Returns

ledgereth.objects.SignedType1Transaction

property rawTransaction

Encoded raw signed transaction

raw_transaction()[source]

Return an encoded raw signed transaction

Encoded signed TX format spec:

0x01 || rlp([chainId, nonce, gasPrice, gasLimit, destination, amount, data, accessList, signatureYParity, signatureR, signatureS])
Returns

Encoded raw signed transaction bytes

transaction_type = 1

The EIP-2718 transaction type

class ledgereth.objects.SignedType2Transaction(chain_id: int, nonce: int, max_priority_fee_per_gas: int, max_fee_per_gas: int, gas_limit: int, destination: bytes, amount: int, data: bytes, access_list: List[Tuple[bytes, List[int]]], y_parity: int, sender_r: int, sender_s: int)[source]

A signed Type 2 transaction.

__init__(chain_id: int, nonce: int, max_priority_fee_per_gas: int, max_fee_per_gas: int, gas_limit: int, destination: bytes, amount: int, data: bytes, access_list: List[Tuple[bytes, List[int]]], y_parity: int, sender_r: int, sender_s: int)[source]

Initialize a signed type 2 transaction

Parameters
  • chain_id – (int) Chain ID

  • nonce – (int) Transaction nonce

  • max_priority_fee_per_gas – (int) Priority fee per gas (in wei) to provide to the miner of the block.

  • max_fee_per_gas – (int) Maximum fee in wei to pay for the transaction. This is not compatible with gas_price.

  • gas_limit – (int) Gas limit

  • destination – (bytes) Destination address

  • amount – (int) Amount of Ether to send in wei

  • data – (bytes) Transaction data

  • access_list – (List[Tuple[bytes, List[int]]]) EIP-2718 Access list

  • y_parity – (int) Parity byte for the signature

  • sender_r – (int) Signature r value

  • sender_s – (int) Signature s value

classmethod from_rawtx(rawtx: bytes) ledgereth.objects.SignedType2Transaction[source]

Instantiate a SignedType2Transaction object from a raw encoded transaction

Parameters

rawtx – (bytes) A raw signed transaction to instantiate with

Returns

ledgereth.objects.SignedType2Transaction

property rawTransaction

Encoded raw signed transaction

raw_transaction()[source]

Return an encoded raw signed transaction

Encoded signed TX format spec:

0x02 || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, amount, data, access_list, signature_y_parity, signature_r, signature_s])
Returns

Encoded raw signed transaction bytes

transaction_type = 2

The EIP-2718 transaction type

class ledgereth.objects.SignedTypedMessage(domain_hash, message_hash, v, r, s)[source]

Signed EIP-812 typed data

__init__(domain_hash, message_hash, v, r, s)[source]

Initialize a singed message

Parameters
  • domain_hash – (bytes) Domain hash that was signed

  • message_hash – (bytes) Message hash that was signed

  • v – (int) Signature v value

  • r – (int) Signature r value

  • s – (int) Signature s value

class ledgereth.objects.Transaction(nonce: int, gas_price: int, gas_limit: int, destination: bytes, amount: int, data: bytes, chain_id: int = 1, dummy1: int = 0, dummy2: int = 0)[source]

Unsigned legacy or EIP-155 transaction

Warning

chain_id for type 0 (“Legacy”) transactions must be less than 4294967295, the largest 32-bit unsigned integer.

Note

A chain_id is set by default (1). It is not required to be a valid legacy transaction, but without it your transaction is suceptible to replay attack. If for some reason you absolutely do not want it in your tx, set it to None.

__init__(nonce: int, gas_price: int, gas_limit: int, destination: bytes, amount: int, data: bytes, chain_id: int = 1, dummy1: int = 0, dummy2: int = 0)[source]

Initialize an unsigned transaction

Parameters
  • nonce – (int) Transaction nonce

  • gas_price – (int) Gas price in wei

  • gas_limit – (int) Gas limit

  • destination – (bytes) Destination address

  • amount – (int) Amount of Ether to send in wei

  • data – (bytes) Transaction data

  • chain_id – (int) Chain ID

  • dummy1 – (int) DO NOT SET

  • dummy2 – (int) DO NOT SET

classmethod from_rawtx(rawtx: bytes) ledgereth.objects.Transaction[source]

Instantiate a Transaction object from a raw encoded transaction

Parameters

rawtx – (bytes) A raw transaction to instantiate with

Returns

ledgereth.objects.Transaction

transaction_type = 0

The EIP-2718 transaction type

class ledgereth.objects.TransactionType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

An Ethereum EIP-2718 transaction type

EIP_1559 = 2

Type-2 (Transaction fee change to max fee and priority fee)

EIP_2930 = 1

Type-1 (Access Lists)

LEGACY = 0

Original and EIP-155

to_byte()[source]

Decode TransactionType to a single byte

class ledgereth.objects.Type1Transaction(chain_id: int, nonce: int, gas_price: int, gas_limit: int, destination: bytes, amount: int, data: bytes, access_list: Optional[List[Tuple[bytes, List[int]]]] = None)[source]

An unsigned Type 1 transaction.

Warning

chain_id for type 1 transactions must be less than 999999999999999, the largest unsigned integer that the device can render on-screen.

Encoded tx format spec:

0x01 || rlp([chainId, nonce, gasPrice, gasLimit, destination, amount, data, accessList])
__init__(chain_id: int, nonce: int, gas_price: int, gas_limit: int, destination: bytes, amount: int, data: bytes, access_list: Optional[List[Tuple[bytes, List[int]]]] = None)[source]

Initialize an unsigned type 2 transaction

Parameters
  • chain_id – (int) Chain ID

  • nonce – (int) Transaction nonce

  • gas_price – (int) Gas price in wei

  • gas_limit – (int) Gas limit

  • destination – (bytes) Destination address

  • amount – (int) Amount of Ether to send in wei

  • data – (bytes) Transaction data

  • access_list – (Optional[List[Tuple[bytes, List[int]]]]) EIP-2718 Access list

classmethod from_rawtx(rawtx: bytes) ledgereth.objects.Type1Transaction[source]

Instantiate a Type1Transaction object from a raw encoded transaction

Parameters

rawtx – (bytes) A raw transaction to instantiate with

Returns

ledgereth.objects.Type1Transaction

transaction_type = 1

The EIP-2718 transaction type

class ledgereth.objects.Type2Transaction(chain_id: int, nonce: int, max_priority_fee_per_gas: int, max_fee_per_gas: int, gas_limit: int, destination: bytes, amount: int, data: bytes, access_list: Optional[List[Tuple[bytes, List[int]]]] = None)[source]

An unsigned Type 2 transaction.

Warning

chain_id for type 2 transactions must be less than 999999999999999, the largest unsigned integer that the device can render on-screen.

Encoded TX format spec:

0x02 || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, amount, data, access_list])
__init__(chain_id: int, nonce: int, max_priority_fee_per_gas: int, max_fee_per_gas: int, gas_limit: int, destination: bytes, amount: int, data: bytes, access_list: Optional[List[Tuple[bytes, List[int]]]] = None)[source]

Initialize an unsigned type 2 transaction

Parameters
  • chain_id – (int) Chain ID

  • nonce – (int) Transaction nonce

  • max_priority_fee_per_gas – (int) Priority fee per gas (in wei) to provide to the miner of the block.

  • max_fee_per_gas – (int) Maximum fee in wei to pay for the transaction. This is not compatible with gas_price.

  • gas_limit – (int) Gas limit

  • destination – (bytes) Destination address

  • amount – (int) Amount of Ether to send in wei

  • data – (bytes) Transaction data

  • access_list – (List[Tuple[bytes, List[int]]]) EIP-2718 Access list

classmethod from_rawtx(rawtx: bytes) ledgereth.objects.Type2Transaction[source]

Instantiate a Type2Transaction object from a raw encoded transaction

Parameters

rawtx – (bytes) A raw transaction to instantiate with

Returns

ledgereth.objects.Type2Transaction

transaction_type = 2

The EIP-2718 transaction type