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
- 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 accountaddress – (
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 transactionbytes
to encode into aledgereth.objects.SerializableTransaction
- Returns
Instantiated
ledgereth.objects.SerializableTransaction
- 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.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 noncegas_price – (
int
) Gas price in weigas_limit – (
int
) Gas limitdestination – (
bytes
) Destination addressamount – (
int
) Amount of Ether to send in weidata – (
bytes
) Transaction datav – (
int
) Signature v valuer – (
int
) Signature r values – (
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
- 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 IDnonce – (
int
) Transaction noncegas_price – (
int
) Gas price in weigas_limit – (
int
) Gas limitdestination – (
bytes
) Destination addressamount – (
int
) Amount of Ether to send in weidata – (
bytes
) Transaction dataaccess_list – (
List[Tuple[bytes, List[int]]]
) EIP-2718 Access listy_parity – (
int
) Parity byte for the signaturesender_r – (
int
) Signature r valuesender_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
- 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 IDnonce – (
int
) Transaction noncemax_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 withgas_price
.gas_limit – (
int
) Gas limitdestination – (
bytes
) Destination addressamount – (
int
) Amount of Ether to send in weidata – (
bytes
) Transaction dataaccess_list – (
List[Tuple[bytes, List[int]]]
) EIP-2718 Access listy_parity – (
int
) Parity byte for the signaturesender_r – (
int
) Signature r valuesender_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
- 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
- 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 toNone
.- __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 noncegas_price – (
int
) Gas price in weigas_limit – (
int
) Gas limitdestination – (
bytes
) Destination addressamount – (
int
) Amount of Ether to send in weidata – (
bytes
) Transaction datachain_id – (
int
) Chain IDdummy1 – (
int
) DO NOT SETdummy2 – (
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
- 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
- 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 IDnonce – (
int
) Transaction noncegas_price – (
int
) Gas price in weigas_limit – (
int
) Gas limitdestination – (
bytes
) Destination addressamount – (
int
) Amount of Ether to send in weidata – (
bytes
) Transaction dataaccess_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
- 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 IDnonce – (
int
) Transaction noncemax_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 withgas_price
.gas_limit – (
int
) Gas limitdestination – (
bytes
) Destination addressamount – (
int
) Amount of Ether to send in weidata – (
bytes
) Transaction dataaccess_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
- transaction_type = 2
The EIP-2718 transaction type