Skip to content

Commit 7689fa2

Browse files
author
maxufeng
committed
[docs] update README.md
1 parent 420111e commit 7689fa2

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ There are three methods of interest:
2626

2727
Example code:
2828
```js
29-
var abi = require('ethereumjs-abi')
29+
var abi = require('@bifproject/ethereumjs-abi')
3030

3131
// returns the encoded binary (as a Buffer) data to be sent
32-
var encoded = abi.rawEncode([ "address" ], [ "0x0000000000000000000000000000000000000000" ])
32+
var encoded = abi.rawEncode([ "address" ], [ 'bid:efcx2eHszCy1zDtNiWdBBnsjG316EU5p' ])
3333

3434
// returns the decoded array of arguments
35-
var decoded = abi.rawDecode([ "address" ], data)
35+
var decoded = abi.stringify([ 'address' ], abi.rawDecode([ "address" ], data))
3636
```
3737

3838
#### Encoding and decoding aided by the JSON ABI definition
3939

4040
Planned for the future is supporting the JSON ABI definition:
4141

4242
```js
43-
var abi = require('ethereumjs-abi')
43+
var abi = require('@bifproject/ethereumjs-abi')
4444

4545
// need to have the ABI definition in JSON as per specification
4646
var tokenAbi = [{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"inputs":[],"type":"constructor"}]
@@ -53,25 +53,25 @@ var decoded = abi.decode(tokenAbi, "balanceOf(uint256 address)", data)
5353
#### Simple encoding and decoding
5454

5555
```js
56-
var abi = require('ethereumjs-abi')
56+
var abi = require('@bifproject/ethereumjs-abi')
5757

5858
// returns the encoded binary (as a Buffer) data to be sent
59-
var encoded = abi.simpleEncode("balanceOf(address):(uint256)", "0x0000000000000000000000000000000000000000")
59+
var encoded = abi.simpleEncode("balanceOf(address):(uint256)", "bid:efcx2eHszCy1zDtNiWdBBnsjG316EU5p")
6060

6161
// returns the decoded array of arguments
6262
var decoded = abi.simpleDecode("balanceOf(address):(uint256)", data)
6363
```
6464

6565
#### Solidity *tightly packed* formats
6666

67-
This library also supports creating Solidity's tightly packed data constructs, which are used together with ```sha3```, ```sha256``` and ```ripemd160``` to create hashes.
67+
This library also supports creating Solidity's tightly packed data constructs, which are used together with ```sha3```, ```sha256``` to create hashes.
6868

6969
Solidity code:
7070
```js
7171
contract HashTest {
7272
function testSha3() returns (bytes32) {
73-
address addr1 = 0x43989fb883ba8111221e89123897538475893837;
74-
address addr2 = 0;
73+
address addr1 = did:bid:efcx2eHszCy1zDtNiWdBBnsjG316EU5p;
74+
address addr2 = 0x000000000000000000000000000000000000000;
7575
uint val = 10000;
7676
uint timestamp = 1448075779;
7777

@@ -82,21 +82,18 @@ contract HashTest {
8282

8383
Creating the same hash using this library:
8484
```js
85-
var abi = require('ethereumjs-abi')
85+
var abi = require('@bifproject/ethereumjs-abi')
8686
var BN = require('bn.js')
8787

8888
abi.soliditySHA3(
8989
[ "address", "address", "uint", "uint" ],
90-
[ new BN("43989fb883ba8111221e89123897538475893837", 16), 0, 10000, 1448075779 ]
90+
[ 'did:bid:ef7g5BDJmHxnTC1Ja25gKEqmDx2AKCFr', '0', 10000, 1448075779 ]
9191
).toString('hex')
9292
```
9393

9494
For the same data structure:
95-
* sha3 will return ```0xc3ab5ca31a013757f26a88561f0ff5057a97dfcc33f43d6b479abc3ac2d1d595```
96-
* sha256 will return ```0x344d8cb0711672efbdfe991f35943847c1058e1ecf515ff63ad936b91fd16231```
97-
* ripemd160 will return ```0x000000000000000000000000a398cc72490f72048efa52c4e92067e8499672e7``` (NOTE: it is 160bits, left padded to 256bits)
98-
99-
Note that ```ripemd160()``` in Solidity returns bytes20 and if you cast it to bytes32, it will be right padded with zeroes.
95+
* sha3 will return ```c94ac1aa7c404ee9ff2308c1c3804b120e3285e595e2a51891a0d102231510f6```
96+
* sha256 will return ```f073ec116d3ac396103258803f193cdd5ed29f384924593e62c091cd1d643f44```
10097

10198
#### Using Serpent types
10299

0 commit comments

Comments
 (0)