Skip to content

Commit

Permalink
Merge pull request #38 from web3p/eip1559
Browse files Browse the repository at this point in the history
EIP1559 SUPPORT
  • Loading branch information
sc0Vu committed Sep 1, 2021
2 parents 7dd97d8 + b98241f commit 8dc1adc
Show file tree
Hide file tree
Showing 8 changed files with 983 additions and 97 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ composer.phar
/vendor/
composer.lock
.DS_Store
.phpunit.result.cache
# Commit your application's lock file http:https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http:https://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
114 changes: 22 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ composer require web3p/ethereum-tx

# Usage

Create a transaction:
## Create a transaction
```php
use Web3p\EthereumTx\Transaction;

Expand All @@ -24,7 +24,7 @@ $transaction = new Transaction([
'gas' => '0x76c0',
'gasPrice' => '0x9184e72a000',
'value' => '0x9184e72a',
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
'data' => ''
]);

// with chainId
Expand All @@ -43,122 +43,52 @@ $transaction = new Transaction([
$transaction = new Transaction('0xf86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83');
```

Sign a transaction:
```php
use Web3p\EthereumTx\Transaction;

$signedTransaction = $transaction->sign('your private key');
```

# API

### Web3p\EthereumTx\Transaction

#### sha3

Returns keccak256 encoding of given data.

> It will be removed in the next version.
`sha3(string $input)`

String input

###### Example

* Encode string.

## Create a EIP1559 transaction
```php
use Web3p\EthereumTx\Transaction;
use Web3p\EthereumTx\EIP1559Transaction;

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

#### serialize

Returns recursive length prefix encoding of transaction data.

`serialize()`

###### Example

* Serialize the transaction data.

## Create a EIP2930 transaction:
```php
use Web3p\EthereumTx\Transaction;
use Web3p\EthereumTx\EIP2930Transaction;

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

#### sign

Returns signed of transaction data.

`sign(string $privateKey)`

String privateKey - hexed private key with zero prefixed.

###### Example

* Sign the transaction data.

## Sign a transaction:
```php
use Web3p\EthereumTx\Transaction;

$transaction = new Transaction([
'nonce' => '0x01',
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
'gas' => '0x76c0',
'gasPrice' => '0x9184e72a000',
'value' => '0x9184e72a',
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
]);
$signedTx = $transaction->sign($stringPrivateKey);
$signedTransaction = $transaction->sign('your private key');
```

#### hash

Returns keccak256 encoding of serialized transaction data.

`hash()`

###### Example

* Hash serialized transaction data.

```php
use Web3p\EthereumTx\Transaction;
# API

$transaction = new Transaction([
'nonce' => '0x01',
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
'gas' => '0x76c0',
'gasPrice' => '0x9184e72a000',
'value' => '0x9184e72a',
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
]);
$hashedTx = $transaction->serialize();
```
https://www.web3p.xyz/ethereumtx.html

# License
MIT
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require-dev": {
"phpunit/phpunit": "~7 | ~8.0"
"phpunit/phpunit": "~7|~8.0"
},
"autoload": {
"psr-4": {
Expand All @@ -23,8 +23,8 @@
}
},
"require": {
"PHP": "^7.1 | ^8.0",
"web3p/rlp": "0.3.3",
"PHP": "^7.1|^8.0",
"web3p/rlp": "0.3.4",
"web3p/ethereum-util": "~0.1.3",
"kornrunner/keccak": "~1",
"simplito/elliptic-php": "~1.0.6"
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
stopOnFailure="false">

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

0 comments on commit 8dc1adc

Please sign in to comment.