Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP1559 SUPPORT #38

Merged
merged 8 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://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
Loading