TypeTransaction

TypeTransaction implements ArrayAccess

It's a base transaction for generating/serializing ethereum type transaction (EIP1559/EIP2930).

Only use this class to generate new type transaction

Tags
author

Peter Lai alk03073135@gmail.com

link
https://www.web3p.xyz
filesource

https://github.com/web3p/ethereum-tx

Interfaces, Classes and Traits

ArrayAccess

Table of Contents

$attributeMap  : array<string|int, mixed>
Attribute map for keeping order of transaction key/value
$privateKey  : KeyPair
Private key instance
$rlp  : RLP
RLP encoding instance
$secp256k1  : EC
secp256k1 elliptic curve instance
$transactionType  : string
Transaction type
$txData  : array<string|int, mixed>
Raw transaction data
$util  : Util
Ethereum util instance
__construct()  : void
construct
__get()  : mixed
Return the value in the transaction with given key or return the protected property value if get(property_name} function is existed.
__set()  : void
Set the value in the transaction with given key or return the protected value if set(property_name} function is existed.
__toString()  : string
Return hash of the ethereum transaction without signature.
getFromAddress()  : string
Recover from address with given signature (r, s, v) if didn't set from.
getTxData()  : array<string|int, mixed>
Return raw ethereum transaction data.
hash()  : string
Return hash of the ethereum transaction with/without signature.
offsetExists()  : bool
Return whether the value is in the transaction with given key.
offsetGet()  : mixed
Return the value in the transaction with given key.
offsetSet()  : void
Set the value in the transaction with given key.
offsetUnset()  : void
Unset the value in the transaction with given key.
serialize()  : Buffer
RLP serialize the ethereum transaction.
sign()  : string
Sign the transaction with given hex encoded private key.
isTransactionTypeValid()  : bool
Return whether transaction type is valid (0x0 <= $transactionType <= 0x7f).

Properties

$attributeMap

Attribute map for keeping order of transaction key/value

protected array<string|int, mixed> $attributeMap = ['from' => ['key' => -1], 'chainId' => ['key' => 0], 'nonce' => ['key' => 1, 'length' => 32, 'allowLess' => true, 'allowZero' => false], 'gasPrice' => ['key' => 2, 'length' => 32, 'allowLess' => true, 'allowZero' => false], 'gasLimit' => ['key' => 3, 'length' => 32, 'allowLess' => true, 'allowZero' => false], 'gas' => ['key' => 3, 'length' => 32, 'allowLess' => true, 'allowZero' => false], 'to' => ['key' => 4, 'length' => 20, 'allowZero' => true], 'value' => ['key' => 5, 'length' => 32, 'allowLess' => true, 'allowZero' => false], 'data' => ['key' => 6, 'allowLess' => true, 'allowZero' => true], 'v' => ['key' => 7, 'allowZero' => true], 'r' => ['key' => 8, 'length' => 32, 'allowZero' => true], 's' => ['key' => 9, 'length' => 32, 'allowZero' => true]]

$secp256k1

secp256k1 elliptic curve instance

protected EC $secp256k1

$transactionType

Transaction type

protected string $transactionType = '00'

$txData

Raw transaction data

protected array<string|int, mixed> $txData = []

Methods

__construct()

construct

public __construct([array<string|int, mixed>|string $txData = [] ]) : void
Parameters
$txData : array<string|int, mixed>|string = []
Return values
void

__get()

Return the value in the transaction with given key or return the protected property value if get(property_name} function is existed.

public __get(string $name) : mixed
Parameters
$name : string

key or protected property name

Return values
mixed

__set()

Set the value in the transaction with given key or return the protected value if set(property_name} function is existed.

public __set(string $name, mixed $value) : void
Parameters
$name : string

key, eg: to

$value : mixed
Return values
void

__toString()

Return hash of the ethereum transaction without signature.

public __toString() : string
Return values
string

hex encoded of the transaction

getFromAddress()

Recover from address with given signature (r, s, v) if didn't set from.

public getFromAddress() : string
Return values
string

hex encoded ethereum address

getTxData()

Return raw ethereum transaction data.

public getTxData() : array<string|int, mixed>
Return values
array<string|int, mixed>

raw ethereum transaction data

hash()

Return hash of the ethereum transaction with/without signature.

public hash([bool $includeSignature = false ]) : string
Parameters
$includeSignature : bool = false

hash with signature

Return values
string

hex encoded hash of the ethereum transaction

offsetExists()

Return whether the value is in the transaction with given key.

public offsetExists(string $offset) : bool
Parameters
$offset : string

key, eg: to

Return values
bool

offsetGet()

Return the value in the transaction with given key.

public offsetGet(string $offset) : mixed
Parameters
$offset : string

key, eg: to

Return values
mixed

value of the transaction

offsetSet()

Set the value in the transaction with given key.

public offsetSet(string $offset, mixed $value) : void
Parameters
$offset : string

key, eg: to

$value : mixed
Return values
void

offsetUnset()

Unset the value in the transaction with given key.

public offsetUnset(string $offset) : void
Parameters
$offset : string

key, eg: to

Return values
void

serialize()

RLP serialize the ethereum transaction.

public serialize() : Buffer
Return values
Buffer

serialized ethereum transaction

sign()

Sign the transaction with given hex encoded private key.

public sign(string $privateKey) : string
Parameters
$privateKey : string

hex encoded private key

Return values
string

hex encoded signed ethereum transaction

isTransactionTypeValid()

Return whether transaction type is valid (0x0 <= $transactionType <= 0x7f).

protected isTransactionTypeValid(int $transactionType) : bool
Parameters
$transactionType : int
Return values
bool

is transaction valid