@@ -12,7 +12,7 @@ composer require web3p/ethereum-tx
1212
1313# Usage
1414
15- Create a transaction:
15+ ## Create a transaction
1616``` php
1717use 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
12484use 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
16494MIT
0 commit comments