Ether Binder
Set of utilities for interacting with Ethereum and it's smart contracts with PHP, with generating ABI bindings and Ethereum-related types
Loading...
Searching...
No Matches
M8B\EtherBinder\Common\Transaction Class Reference
Inheritance diagram for M8B\EtherBinder\Common\Transaction:
M8B\EtherBinder\Common\BinarySerializableInterface M8B\EtherBinder\Common\LegacyTransaction M8B\EtherBinder\Common\LondonTransaction M8B\EtherBinder\Common\AccessListTransaction M8B\EtherBinder\Common\CancunTransaction

Public Member Functions

 encodeBin ()
 
 encodeBinForSigning (?int $chainId)
 
 transactionType ()
 
 ecRecover ()
 
 useRpcEstimatesWithBump (AbstractRPC $rpc, ?Address $from, int $bumpGasPercentage, int $bumpFeePercentage)
 
 toBin ()
 
 toHex ()
 
 encodeHexForSigning (?int $chainId)
 
 encodeHex ()
 
 setNonce (int $nonce)
 
 nonce ()
 
 setGasLimit (int $gasLimit)
 
 gasLimit ()
 
 totalGasPrice ()
 
 setValueFmt (float|int|string|OOGmp $human, int|string|EtherFormats $format=EtherFormats::ETHER)
 
 setValue (OOGmp $valueWEI)
 
 value ()
 
 valueFmt (int $finalDecimals, int|string|EtherFormats $format=EtherFormats::ETHER)
 
 setTo (?Address $address)
 
 to ()
 
 setDataBin (string $dataBin)
 
 setDataHex (string $dataHex)
 
 dataHex ()
 
 dataBin ()
 
 v ()
 
 r ()
 
 s ()
 
 isSigned ()
 
 hash ()
 
 getSigningHash (?int $chainId)
 
 sign (Key $key, ?int $chainId)
 
 calculateV (OOGmp $recovery)
 
 useRpcEstimates (AbstractRPC $rpc, Address $from)
 
 deployAddress ()
 
 signature ()
 
 setSignature (Signature $s)
 
 nonceFromRPC (Address $from, AbstractRPC $rpc)
 

Static Public Member Functions

static decodeHex (string $rlp)
 
static decodeBin (string $rlp)
 
static fromHex (string $hex)
 
static fromBin (string $bin)
 
static fromRPCArr (array $rpcArr)
 

Protected Member Functions

 blanksFromRPCArr (array $rpcArr)
 
 setInnerFromRLPValues (array $rlpValues)
 
 setGasPriceOrBaseFee (OOGmp $fee)
 

Protected Attributes

bool $signed = false
 
int $nonce = 0
 
int $gas = 0
 
OOGmp $gasPrice
 
OOGmp $value
 
Address $to = null
 
string $dataBin = ""
 
OOGmp $v
 
OOGmp $r
 
OOGmp $s
 
int $chainId = null
 

Detailed Description

Transaction serves as an abstract base class for Ethereum transactions. It represents any transaction, can be signed or unsigned.

Author
DubbaThony

Member Function Documentation

◆ blanksFromRPCArr()

M8B\EtherBinder\Common\Transaction::blanksFromRPCArr ( array $rpcArr)
abstractprotected

◆ calculateV()

M8B\EtherBinder\Common\Transaction::calculateV ( OOGmp $recovery)

Calculates the recovery id (v) for signature accounting for EIP155 (replay protection).

Parameters
OOGmp$recoveryRecovery id before chain id calculations.
Returns
OOGmp Final recovery id.

Reimplemented in M8B\EtherBinder\Common\AccessListTransaction, and M8B\EtherBinder\Common\LondonTransaction.

◆ dataBin()

M8B\EtherBinder\Common\Transaction::dataBin ( )

Gets the binary data payload of the transaction.

Returns
string The binary data.

◆ dataHex()

M8B\EtherBinder\Common\Transaction::dataHex ( )

Gets the transaction data in hex format.

Returns
string Data in hex.

◆ decodeBin()

static M8B\EtherBinder\Common\Transaction::decodeBin ( string $rlp)
static

Decodes a binary RLP-encoded transaction. Accepts both legacy formatting and typed transaction.

Parameters
string$rlpThe RLP-encoded transaction as a binary string.
Returns
static The decoded Transaction object.
Exceptions
BadAddressChecksumException
EthBinderLogicException
EthBinderRuntimeException
InvalidHexException
InvalidHexLengthException
NotSupportedException

◆ decodeHex()

static M8B\EtherBinder\Common\Transaction::decodeHex ( string $rlp)
static

Decodes a hexadecimal RLP-encoded transaction. Accepts both legacy formatting and typed transaction.

Parameters
string$rlpThe RLP-encoded transaction as a hexadecimal string.
Returns
static The decoded Transaction object.
Exceptions
BadAddressChecksumException
EthBinderLogicException
EthBinderRuntimeException
InvalidHexException
InvalidHexLengthException
NotSupportedException

◆ deployAddress()

M8B\EtherBinder\Common\Transaction::deployAddress ( )

Gets the address where the contract will be deployed if it's deploy transaction. If it is not deploy transaction, it will return null address - Address::NULL()

Returns
Address Address where contract will be deployed.
Exceptions
EthBinderLogicException
InvalidLengthException

◆ ecRecover()

M8B\EtherBinder\Common\Transaction::ecRecover ( )
abstract
Exceptions
EthBinderRuntimeException
EthBinderLogicException
InvalidLengthException

Reimplemented in M8B\EtherBinder\Common\AccessListTransaction, M8B\EtherBinder\Common\LegacyTransaction, and M8B\EtherBinder\Common\LondonTransaction.

◆ encodeBin()

M8B\EtherBinder\Common\Transaction::encodeBin ( )
abstract

◆ encodeBinForSigning()

M8B\EtherBinder\Common\Transaction::encodeBinForSigning ( ?int $chainId)
abstract

◆ encodeHex()

M8B\EtherBinder\Common\Transaction::encodeHex ( )

Encodes the transaction into a hexadecimal string.

Returns
string The hexadecimal encoded transaction.
Exceptions
EthBinderArgumentException

◆ encodeHexForSigning()

M8B\EtherBinder\Common\Transaction::encodeHexForSigning ( ?int $chainId)

Encodes the transaction into a hexadecimal string for signing purposes (which differs from encoding for storage or transfer. Difference is for example missing fields).

Parameters
?int$chainIdThe chain ID for the transaction.
Returns
string The hexadecimal encoded transaction.
Exceptions
EthBinderArgumentException

◆ fromBin()

static M8B\EtherBinder\Common\Transaction::fromBin ( string $bin)
static

Alias function for decodeBin()

See also
static::decodeBin()
Parameters
string$bin
Returns
static
Exceptions
BadAddressChecksumException
EthBinderLogicException
EthBinderRuntimeException
InvalidHexException
InvalidHexLengthException
NotSupportedException

Implements M8B\EtherBinder\Common\BinarySerializableInterface.

◆ fromHex()

static M8B\EtherBinder\Common\Transaction::fromHex ( string $hex)
static

Alias function for decodeHex()

See also
static::decodeHex()
Parameters
string$hex
Returns
static
Exceptions
BadAddressChecksumException
EthBinderLogicException
EthBinderRuntimeException
InvalidHexException
InvalidHexLengthException
NotSupportedException

Implements M8B\EtherBinder\Common\BinarySerializableInterface.

◆ fromRPCArr()

static M8B\EtherBinder\Common\Transaction::fromRPCArr ( array $rpcArr)
static

Creates a transaction from an RPC array.

Parameters
array$rpcArrThe array containing transaction details from RPC.
Returns
static The created Transaction object.
Exceptions
BadAddressChecksumException
NotSupportedException
InvalidHexLengthException
EthBinderLogicException
InvalidHexException
HexBlobNotEvenException

◆ gasLimit()

M8B\EtherBinder\Common\Transaction::gasLimit ( )

Gets the gas limit of the transaction.

Returns
int The gas limit value.

◆ getSigningHash()

M8B\EtherBinder\Common\Transaction::getSigningHash ( ?int $chainId)

Calculates the hash used for signing the transaction.

Parameters
int | null$chainIdOptional chain ID.
Returns
Hash The signing hash.
Exceptions
InvalidLengthException
EthBinderLogicException

◆ hash()

M8B\EtherBinder\Common\Transaction::hash ( )

Calculates the transaction hash.

Returns
Hash The transaction hash.
Exceptions
EthBinderLogicException

◆ isSigned()

M8B\EtherBinder\Common\Transaction::isSigned ( )

Checks if the transaction is signed.

Returns
bool True if signed, false otherwise.

◆ nonce()

M8B\EtherBinder\Common\Transaction::nonce ( )

Gets the nonce of the transaction.

Returns
int The nonce value.

◆ nonceFromRPC()

M8B\EtherBinder\Common\Transaction::nonceFromRPC ( Address $from,
AbstractRPC $rpc )

Convenience function that fetches nonce from RPC and places it into transaction. If new nonce mismatches currently set nonce, it invalidates signature.

Parameters
Address$fromAddress of which to set next nonce.
AbstractRPC$rpcRPC to query transaction count from.
Returns
Transaction self for chainable API.
Exceptions
EthBinderRuntimeException
RPCGeneralException
RPCInvalidResponseParamException
RPCNotFoundException

◆ r()

M8B\EtherBinder\Common\Transaction::r ( )

Gets the ECDSA 'r' value of the signature.

Returns
OOGmp The 'r' value.

◆ s()

M8B\EtherBinder\Common\Transaction::s ( )

Gets the ECDSA 's' value of the signature.

Returns
OOGmp The 's' value.

◆ setDataBin()

M8B\EtherBinder\Common\Transaction::setDataBin ( string $dataBin)

Sets the data payload for the transaction using binary blob. This invalidates signature if data differs from existing data.

Parameters
string$dataBinThe binary data.
Returns
static The updated Transaction object.

◆ setDataHex()

M8B\EtherBinder\Common\Transaction::setDataHex ( string $dataHex)

Sets the data for the transaction using a hex string. This invalidates signature if data differs from existing data.

Parameters
string$dataHexData in hex format.
Returns
static
Exceptions
HexBlobNotEvenException
InvalidHexException

◆ setGasLimit()

M8B\EtherBinder\Common\Transaction::setGasLimit ( int $gasLimit)

Sets the gas limit for the transaction. This invalidates signature if data differs from existing data.

Parameters
int$gasLimitThe gas limit value.
Returns
static The updated Transaction object.

◆ setInnerFromRLPValues()

M8B\EtherBinder\Common\Transaction::setInnerFromRLPValues ( array $rlpValues)
abstractprotected
Exceptions
BadAddressChecksumException
EthBinderLogicException
InvalidHexLengthException
InvalidHexException
EthBinderRuntimeException

Reimplemented in M8B\EtherBinder\Common\AccessListTransaction, M8B\EtherBinder\Common\CancunTransaction, M8B\EtherBinder\Common\LegacyTransaction, and M8B\EtherBinder\Common\LondonTransaction.

◆ setNonce()

M8B\EtherBinder\Common\Transaction::setNonce ( int $nonce)

Sets the nonce for the transaction. This invalidates signature if data differs from existing data.

Parameters
int$nonceThe nonce value.
Returns
static The updated Transaction object.

◆ setSignature()

M8B\EtherBinder\Common\Transaction::setSignature ( Signature $s)

Sets the signature. Note that there is no guarantee the signature will work correctly. This is for advanced use only. Ensure to properly account for EIP 155 in signature's V.

Returns
static The updated Transaction object.

◆ setTo()

M8B\EtherBinder\Common\Transaction::setTo ( ?Address $address)

Sets the recipient address for the transaction. If it's null, the transaction is contract deploy transaction. This invalidates signature if data differs from existing data.

Parameters
Address | null$addressThe Address object or null. If null, the transaction is contract deploy
Returns
static The updated Transaction object.

◆ setValue()

M8B\EtherBinder\Common\Transaction::setValue ( OOGmp $valueWEI)

Sets the value for the transaction. This invalidates signature if data differs from existing data.

Parameters
OOGmp$valueWEIThe value in Wei.
Returns
static The updated Transaction object.

◆ setValueFmt()

M8B\EtherBinder\Common\Transaction::setValueFmt ( float|int|string|OOGmp $human,
int|string|EtherFormats $format = EtherFormats::ETHER )

Sets the value for the transaction using WeiFormatter. Accepts "human" input. This invalidates signature if data differs from existing data.

Parameters
float | int | string | OOGmp$human
int | string | EtherFormats$format
Returns
static The updated Transaction object.

◆ sign()

M8B\EtherBinder\Common\Transaction::sign ( Key $key,
?int $chainId )

Signs the transaction.

Parameters
Key$keyPrivate key for signing.
int | null$chainIdOptional chain ID.
Returns
static
Exceptions
InvalidLengthException
EthBinderLogicException

◆ signature()

M8B\EtherBinder\Common\Transaction::signature ( )

Gets the signature in wrapper object.

Returns
Signature The signature details.

◆ to()

M8B\EtherBinder\Common\Transaction::to ( )

Gets the recipient address of the transaction, null if it's deploy transaction.

Returns
Address|null The recipient address or null (deploy).

◆ toBin()

M8B\EtherBinder\Common\Transaction::toBin ( )

Alias function for encodeBin()

Returns
string
Exceptions
EthBinderArgumentException
See also
static::encodeBin()

Implements M8B\EtherBinder\Common\BinarySerializableInterface.

◆ toHex()

M8B\EtherBinder\Common\Transaction::toHex ( )

Alias function for encodeHex()

See also
static::encodeHex()
Returns
string
Exceptions
EthBinderArgumentException

Implements M8B\EtherBinder\Common\BinarySerializableInterface.

◆ totalGasPrice()

M8B\EtherBinder\Common\Transaction::totalGasPrice ( )

Gets the total gas price for the transaction.

Returns
OOGmp Total gas price.

Reimplemented in M8B\EtherBinder\Common\LondonTransaction.

◆ transactionType()

M8B\EtherBinder\Common\Transaction::transactionType ( )
abstract

◆ useRpcEstimates()

M8B\EtherBinder\Common\Transaction::useRpcEstimates ( AbstractRPC $rpc,
Address $from )

Estimates gas and fee values using from RPC, trying to use conservative values. This invalidates signature if data differs from existing data

Parameters
AbstractRPC$rpcThe RPC client.
Address$fromThe sender address.
Returns
static The updated Transaction object.
Exceptions
RPCGeneralException
RPCNotFoundException
RPCInvalidResponseParamException
EthBinderLogicException
EthBinderRuntimeException

◆ useRpcEstimatesWithBump()

M8B\EtherBinder\Common\Transaction::useRpcEstimatesWithBump ( AbstractRPC $rpc,
?Address $from,
int $bumpGasPercentage,
int $bumpFeePercentage )
abstract
Exceptions
RPCGeneralException
RPCNotFoundException
EthBinderLogicException
RPCInvalidResponseParamException
EthBinderRuntimeException

Reimplemented in M8B\EtherBinder\Common\LegacyTransaction, and M8B\EtherBinder\Common\LondonTransaction.

◆ v()

M8B\EtherBinder\Common\Transaction::v ( )

Gets the ECDSA 'v' value of the signature.

Returns
OOGmp The 'v' value.

◆ value()

M8B\EtherBinder\Common\Transaction::value ( )

Gets the value of the transaction.

Returns
OOGmp The value in Wei.

◆ valueFmt()

M8B\EtherBinder\Common\Transaction::valueFmt ( int $finalDecimals,
int|string|EtherFormats $format = EtherFormats::ETHER )

Gets the value of the transaction and formats it with WeiFormatter, proxying params to it.

Parameters
int$finalDecimalsNumber of decimals for formatting.
int | string | EtherFormats$formatEther format.
Returns
string Formatted value.

The documentation for this class was generated from the following file: