Transaction

Transaction implements ArrayAccess

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

use Web3p\EthereumTx\Transaction;

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

// generate transaction instance with hex encoded transaction
$transaction = new Transaction('0xf86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83');
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

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
$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.

Properties

$attributeMap

Attribute map for keeping order of transaction key/value

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

$privateKey

Private key instance

protected KeyPair $privateKey

$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