EthObject
Trying to serialize Ethereum Trie / LevelDB data from hex, buffers and rpc into the same format is tough. This library aims to solve that with re-usable and composable objects that you can just call Object.from to ingest new data.
EthObjects hold Ethereum bare bones data with lots of helper functions for viewing and moving them in and out of other popular formats.
npm install eth-object
The following objects are supported:
const { Account, Header, Log, Proof, Receipt, Transaction } = require('eth-object')
Formating
The data formats used/returned for account, header
, log
, proof
, receipt
, and transaction
are eth-object
s. They mimic the native Ethereum format of being arrays of byteArrays and nested arrays (of the same). This is the format you would find in the native database after being rlp-decoded.
An account, for example, will look like this:
Its a 4-item array of bytearrays representing the nonce, balance, storageRoot, and codeHash respectively.
But they not just simple arrays that do this:
console.log(account[0])
They also have helper methods for:
- The object's named fields property:
console.log(account.nonce)
- Conversion to printable formats
console.log(account.toJson())
- Conversion to the native bytes:
console.log(account.buffer)
- A text-pastable version of the bytes
console.log(account.hex)
And they can be created from a direct RPC result or any other format that you may find yourself with:
Account.fromRpc(rpcResult)
Account.fromHex(hexString)
Account.fromBuffer(Bytes)
Account.fromRaw(nativeArray)