EIP1559Transaction

EIP1559Transaction extends TypeTransaction

It's a instance for generating/serializing ethereum eip1559 transaction.

use Web3p\EthereumTx\EIP1559Transaction;

// generate transaction instance with transaction parameters
$transaction = new EIP1559Transaction([
'nonce' => '0x01',
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
'maxPriorityFeePerGas' => '0x9184e72a000',
'maxFeePerGas' => '0x9184e72a000',
'gas' => '0x76c0',
'value' => '0x9184e72a',
'chainId' => 1, // required
'accessList' => [],
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
]);

// generate transaction instance with hex encoded transaction
$transaction = new EIP1559Transaction('0x02f86c04158504a817c8008504a817c8008252089435353535353535353535353535353535353535358080c080a03fd48c8a173e9669c33cb5271f03b1af4f030dc8315be8ec9442b7fbdde893c8a010af381dab1df3e7012a3c8421d65a810859a5dd9d58991ad7c07f12d0c651c7');
After generate transaction instance, you can sign transaction with your private key.
<code>
$signedTransaction = $transaction->sign('your private key');

Then you can send serialized transaction to ethereum through http rpc with web3.php.

$hashedTx = $transaction->serialize();
Tags
author

Peter Lai alk03073135@gmail.com

link
https://www.web3p.xyz
filesource

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

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], 'maxPriorityFeePerGas' => ['key' => 2, 'length' => 32, 'allowLess' => true, 'allowZero' => false], 'maxFeePerGas' => ['key' => 3, 'length' => 32, 'allowLess' => true, 'allowZero' => false], 'gasLimit' => ['key' => 4, 'length' => 32, 'allowLess' => true, 'allowZero' => false], 'gas' => ['key' => 4, 'length' => 32, 'allowLess' => true, 'allowZero' => false], 'to' => ['key' => 5, 'length' => 20, 'allowZero' => true], 'value' => ['key' => 6, 'length' => 32, 'allowLess' => true, 'allowZero' => false], 'data' => ['key' => 7, 'allowLess' => true, 'allowZero' => true], 'accessList' => ['key' => 8, 'allowLess' => true, 'allowZero' => true, 'allowArray' => true], 'v' => ['key' => 9, 'allowZero' => true], 'r' => ['key' => 10, 'length' => 32, 'allowZero' => true], 's' => ['key' => 11, 'length' => 32, 'allowZero' => true]]

$secp256k1

secp256k1 elliptic curve instance

protected EC $secp256k1

$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