Skip to content

Commit 8dc1adc

Browse files
authored
Merge pull request #38 from web3p/eip1559
EIP1559 SUPPORT
2 parents 7dd97d8 + b98241f commit 8dc1adc

File tree

8 files changed

+983
-97
lines changed

8 files changed

+983
-97
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ composer.phar
22
/vendor/
33
composer.lock
44
.DS_Store
5+
.phpunit.result.cache
56
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
67
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
78
# composer.lock

README.md

Lines changed: 22 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ composer require web3p/ethereum-tx
1212

1313
# Usage
1414

15-
Create a transaction:
15+
## Create a transaction
1616
```php
1717
use Web3p\EthereumTx\Transaction;
1818

@@ -24,7 +24,7 @@ $transaction = new Transaction([
2424
'gas' => '0x76c0',
2525
'gasPrice' => '0x9184e72a000',
2626
'value' => '0x9184e72a',
27-
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
27+
'data' => ''
2828
]);
2929

3030
// with chainId
@@ -43,122 +43,52 @@ $transaction = new Transaction([
4343
$transaction = new Transaction('0xf86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83');
4444
```
4545

46-
Sign a transaction:
47-
```php
48-
use Web3p\EthereumTx\Transaction;
49-
50-
$signedTransaction = $transaction->sign('your private key');
51-
```
52-
53-
# API
54-
55-
### Web3p\EthereumTx\Transaction
56-
57-
#### sha3
58-
59-
Returns keccak256 encoding of given data.
60-
61-
> It will be removed in the next version.
62-
63-
`sha3(string $input)`
64-
65-
String input
66-
67-
###### Example
68-
69-
* Encode string.
70-
46+
## Create a EIP1559 transaction
7147
```php
72-
use Web3p\EthereumTx\Transaction;
48+
use Web3p\EthereumTx\EIP1559Transaction;
7349

74-
$transaction = new Transaction([
50+
// generate transaction instance with transaction parameters
51+
$transaction = new EIP1559Transaction([
7552
'nonce' => '0x01',
7653
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
7754
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
55+
'maxPriorityFeePerGas' => '0x9184e72a000',
56+
'maxFeePerGas' => '0x9184e72a000',
7857
'gas' => '0x76c0',
79-
'gasPrice' => '0x9184e72a000',
8058
'value' => '0x9184e72a',
81-
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
59+
'chainId' => 1, // required
60+
'accessList' => [],
61+
'data' => ''
8262
]);
83-
$hashedString = $transaction->sha3('web3p');
8463
```
8564

86-
#### serialize
87-
88-
Returns recursive length prefix encoding of transaction data.
89-
90-
`serialize()`
91-
92-
###### Example
93-
94-
* Serialize the transaction data.
95-
65+
## Create a EIP2930 transaction:
9666
```php
97-
use Web3p\EthereumTx\Transaction;
67+
use Web3p\EthereumTx\EIP2930Transaction;
9868

99-
$transaction = new Transaction([
69+
// generate transaction instance with transaction parameters
70+
$transaction = new EIP2930Transaction([
10071
'nonce' => '0x01',
10172
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
10273
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
10374
'gas' => '0x76c0',
104-
'gasPrice' => '0x9184e72a000',
10575
'value' => '0x9184e72a',
106-
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
76+
'chainId' => 1, // required
77+
'accessList' => [],
78+
'data' => ''
10779
]);
108-
$serializedTx = $transaction->serialize();
10980
```
11081

111-
#### sign
112-
113-
Returns signed of transaction data.
114-
115-
`sign(string $privateKey)`
116-
117-
String privateKey - hexed private key with zero prefixed.
118-
119-
###### Example
120-
121-
* Sign the transaction data.
122-
82+
## Sign a transaction:
12383
```php
12484
use Web3p\EthereumTx\Transaction;
12585

126-
$transaction = new Transaction([
127-
'nonce' => '0x01',
128-
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
129-
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
130-
'gas' => '0x76c0',
131-
'gasPrice' => '0x9184e72a000',
132-
'value' => '0x9184e72a',
133-
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
134-
]);
135-
$signedTx = $transaction->sign($stringPrivateKey);
86+
$signedTransaction = $transaction->sign('your private key');
13687
```
13788

138-
#### hash
139-
140-
Returns keccak256 encoding of serialized transaction data.
141-
142-
`hash()`
143-
144-
###### Example
145-
146-
* Hash serialized transaction data.
147-
148-
```php
149-
use Web3p\EthereumTx\Transaction;
89+
# API
15090

151-
$transaction = new Transaction([
152-
'nonce' => '0x01',
153-
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
154-
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
155-
'gas' => '0x76c0',
156-
'gasPrice' => '0x9184e72a000',
157-
'value' => '0x9184e72a',
158-
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
159-
]);
160-
$hashedTx = $transaction->serialize();
161-
```
91+
https://www.web3p.xyz/ethereumtx.html
16292

16393
# License
16494
MIT

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require-dev": {
13-
"phpunit/phpunit": "~7 | ~8.0"
13+
"phpunit/phpunit": "~7|~8.0"
1414
},
1515
"autoload": {
1616
"psr-4": {
@@ -23,8 +23,8 @@
2323
}
2424
},
2525
"require": {
26-
"PHP": "^7.1 | ^8.0",
27-
"web3p/rlp": "0.3.3",
26+
"PHP": "^7.1|^8.0",
27+
"web3p/rlp": "0.3.4",
2828
"web3p/ethereum-util": "~0.1.3",
2929
"kornrunner/keccak": "~1",
3030
"simplito/elliptic-php": "~1.0.6"

phpunit.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
convertNoticesToExceptions="true"
88
convertWarningsToExceptions="true"
99
processIsolation="false"
10-
stopOnFailure="false"
11-
syntaxCheck="false">
10+
stopOnFailure="false">
1211

1312
<testsuite name="Ethereum tx unit test">
1413
<directory suffix="Test.php">./test/unit</directory>

0 commit comments

Comments
 (0)