Skip to content

Commit

Permalink
Merge pull request #3 from sc0Vu/master
Browse files Browse the repository at this point in the history
v0.2
  • Loading branch information
sc0Vu committed Mar 20, 2018
2 parents 20406b1 + fd47d79 commit 1bc8e54
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 62 deletions.
File renamed without changes.
125 changes: 122 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ composer require web3p/ethereum-tx

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

// without chainId
$transaction = new Transaction([
'nonce' => '0x01',
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
Expand All @@ -25,18 +26,136 @@ $transaction = new Transaction([
'value' => '0x9184e72a',
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
]);

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

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

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

# API

Todo.
### 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.

```php
use Web3p\EthereumTx\Transaction;

$transaction = new Transaction([
'nonce' => '0x01',
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
'gas' => '0x76c0',
'gasPrice' => '0x9184e72a000',
'value' => '0x9184e72a',
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
]);
$hashedString = $transaction->sha3('web3p');
```

#### serialize

Returns recursive length prefix encoding of transaction data.

`serialize()`

###### Example

* Serialize the transaction data.

```php
use Web3p\EthereumTx\Transaction;

$transaction = new Transaction([
'nonce' => '0x01',
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
'gas' => '0x76c0',
'gasPrice' => '0x9184e72a000',
'value' => '0x9184e72a',
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
]);
$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.

```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);
```

#### hash

Returns keccak256 encoding of serialized transaction data.

`hash()`

###### Example

* Hash serialized transaction data.

```php
use Web3p\EthereumTx\Transaction;

$transaction = new Transaction([
'nonce' => '0x01',
'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
'gas' => '0x76c0',
'gasPrice' => '0x9184e72a000',
'value' => '0x9184e72a',
'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
]);
$hashedTx = $transaction->serialize();
```

# License
MIT
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
],
"minimum-stability": "dev",
"require-dev": {
"phpunit/phpunit": "~6.0"
"phpunit/phpunit": "^6.1"
},
"autoload": {
"psr-4": {
"EthereumTx\\": "src/"
"Web3p\\EthereumTx\\": "src/"
}
},
"autoload-dev": {
Expand All @@ -24,8 +24,8 @@
}
},
"require": {
"web3p/rlp": "dev-master",
"web3p/secp256k1": "dev-master",
"kornrunner/keccak": "dev-master"
"web3p/rlp": "~0.2",
"web3p/secp256k1": "~0.2",
"kornrunner/keccak": "~1"
}
}

0 comments on commit 1bc8e54

Please sign in to comment.