{"name":"ethereumjs-account","version":"1.0.2","description":"a help module for ethereum account schema","main":"index.js","repository":{"type":"git","url":"git+https://github.com/ethereum/ethereumjs-account.git"},"scripts":{"test":"standard"},"keywords":["ethereum","account"],"author":{"name":"mjbecze","url":"mjbecze@gmail.com"},"license":"GPL-2.0","bugs":{"url":"https://github.com/ethereum/ethereumjs-account/issues"},"homepage":"https://github.com/ethereum/ethereumjs-account#readme","dependencies":{"ethereumjs-util":"2.0.1","rlp":"2.0.0"},"devDependencies":{"standard":"^5.3.1"},"gitHead":"cb277dff8dc5d9814a9b3c30954ca1ca8008c83f","_id":"ethereumjs-account@1.0.2","_shasum":"d5336235a7c51ba4d16d70bb025d12f72152fcab","_from":".","_npmVersion":"3.3.3","_nodeVersion":"4.0.0","_npmUser":{"name":"null_radix","email":"mjbecze@gmail.com"},"dist":{"shasum":"d5336235a7c51ba4d16d70bb025d12f72152fcab","tarball":"http://registry-npm.ywwl.com/ethereumjs-account/download/ethereumjs-account-1.0.2.tgz","integrity":"sha512-XTn2zY7+QkDAFpBGeMfirLQdIMAVFyTEIvYG9XG5YzLRrB1X7oMZsZfPEfW21IAxDKtejjKWnc+4Z1U05BlSKw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFr7AO64ZTgcpkRumT8wcA0J8FUtcRX1EIXGOpmi9XbxAiBGMsZiUPgderLLkur1TNaUoEY5AG9iinWTTnZhsRi0YQ=="}],"size":9338,"noattachment":false,"key":"/ethereumjs-account/-/ethereumjs-account-1.0.2.tgz"},"maintainers":[{"name":"null_radix","email":"mjbecze@gmail.com"}],"directories":{},"readme":"# SYNOPSIS\n\n[![NPM Package](https://img.shields.io/npm/v/ethereumjs-account.svg?style=flat-square)](https://www.npmjs.org/package/ethereumjs-account)\n[![Build Status](https://travis-ci.org/ethereumjs/ethereumjs-account.svg?branch=master)](https://travis-ci.org/ethereumjs/ethereumjs-account)\n[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-account.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethereumjs-account)\n[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)\n\nThis library eases the handling of Ethereum accounts, where accounts can be either external accounts\nor contracts (see\n[Account Types](http://ethdocs.org/en/latest/contracts-and-transactions/account-types-gas-and-transactions.html) docs).\n\nNote that the library is not meant to be used to handle your wallet accounts, use e.g. the\n[web3-eth-personal](http://web3js.readthedocs.io/en/1.0/web3-eth-personal.html) package from the\n`web3.js` library for that. This is just a semantic wrapper to ease the use of account data and\nprovide functionality for reading and writing accounts from and to the Ethereum state trie.\n\n# INSTALL\n\n`npm install ethereumjs-account`\n\n# BROWSER\n\nThis module work with `browserify`.\n\n# API\n\n- [`new Account([data])`](#new-accountdata)\n- [`Account` Properties](#account-properties)\n- [`Account` Methods](#account-methods)\n  - [`account.isEmpty()`](#accountisempty)\n  - [`account.isContract()`](#accountiscontract)\n  - [`account.serialize()`](#accountserialize)\n  - [`account.toJSON()`](#accounttojson)\n  - [`account.getCode(trie, cb)`](#accountgetcodetrie-cb)\n  - [`account.setCode(trie, code, cb)`](#accountsetcodetrie-code-cb)\n  - [`account.getStorage(trie, key, cb)`](#accountgetstoragetrie-key-cb)\n  - [`account.setStorage(trie, key, val, cb)`](#accountsetstoragetrie-key-val-cb)\n\n### `new Account([data])`\n\nCreates a new account object\n\n- `data` - an account can be initialized with either a `buffer` containing the RLP serialized account.\n  Or an `Array` of buffers relating to each of the account Properties, listed in order below. For example:\n\n```javascript\nvar raw = [\n  '0x02', //nonce\n  '0x0384', //balance\n  '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', //stateRoot\n  '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470', //codeHash\n]\n\nvar account = new Account(raw)\n```\n\nOr lastly an `Object` containing the Properties of the account:\n\n```javascript\nvar raw = {\n  nonce: '',\n  balance: '0x03e7',\n  stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',\n  codeHash: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',\n}\n\nvar account = new Account(raw)\n```\n\nFor `Object` and `Array` each of the elements can either be a `Buffer`, hex `String`, `Number`, or an object with a `toBuffer` method such as `Bignum`.\n\n### `Account` Properties\n\n- `nonce` - The account's nonce.\n- `balance` - The account's balance in wei.\n- `stateRoot` - The stateRoot for the storage of the contract.\n- `codeHash` - The hash of the code of the contract.\n\n### `Account` Methods\n\n#### `account.isEmpty()`\n\nReturns a `Boolean` determining if the account is empty.\n\n#### `account.isContract()`\n\nReturns a `Boolean` deteremining if the account is a contract.\n\n#### `account.serialize()`\n\nReturns the RLP serialization of the account as a `Buffer`.\n\n#### `account.toJSON([object])`\n\nReturns the account as JSON.\n\n- `object` - A `Boolean` that defaults to false. If `object` is true then this will return an `Object`, else it will return an `Array`.\n\n#### `account.getCode(trie, cb)`\n\nFetches the code from the trie.\n\n- `trie` - The [trie](https://github.com/ethereumjs/merkle-patricia-tree) storing the accounts.\n- `cb` - The callback.\n\n#### `account.setCode(trie, code, cb)`\n\nStores the code in the trie.\n\n- `trie` - The [trie](https://github.com/ethereumjs/merkle-patricia-tree) storing the accounts.\n- `code` - A `Buffer`.\n- `cb` - The callback.\n\nExample for `getCode` and `setCode`:\n\n```javascript\n// Requires manual merkle-patricia-tree install\nconst SecureTrie = require('merkle-patricia-tree/secure')\nconst Account = require('./index.js').default\n\nlet code = Buffer.from(\n  '73095e7baea6a6c7c4c2dfeb977efac326af552d873173095e7baea6a6c7c4c2dfeb977efac326af552d873157',\n  'hex',\n)\n\nlet raw = {\n  nonce: '',\n  balance: '0x03e7',\n  stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',\n  codeHash: '0xb30fb32201fe0486606ad451e1a61e2ae1748343cd3d411ed992ffcc0774edd4',\n}\n\nlet account = new Account(raw)\nlet trie = new SecureTrie()\n\naccount.setCode(trie, code, function(err, codeHash) {\n  console.log(`Code with hash 0x${codeHash.toString('hex')} set to trie`)\n  account.getCode(trie, function(err, code) {\n    console.log(`Code ${code.toString('hex')} read from trie`)\n  })\n})\n```\n\n#### `account.getStorage(trie, key, cb)`\n\nFetches `key` from the account's storage.\n\n#### `account.setStorage(trie, key, val, cb)`\n\nStores a `val` at the `key` in the contract's storage.\n\nExample for `getStorage` and `setStorage`:\n\n```javascript\n// Requires manual merkle-patricia-tree install\nconst SecureTrie = require('merkle-patricia-tree/secure')\nconst Account = require('./index.js').default\n\nlet raw = {\n  nonce: '',\n  balance: '0x03e7',\n  stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',\n  codeHash: '0xb30fb32201fe0486606ad451e1a61e2ae1748343cd3d411ed992ffcc0774edd4',\n}\n\nlet account = new Account(raw)\nlet trie = new SecureTrie()\n\nlet key = Buffer.from('0000000000000000000000000000000000000000', 'hex')\nlet value = Buffer.from('01', 'hex')\n\naccount.setStorage(trie, key, value, function(err, value) {\n  account.getStorage(trie, key, function(err, value) {\n    console.log(`Value ${value.toString('hex')} set and retrieved from trie.`)\n  })\n})\n```\n","publish_time":1443073823498,"_cnpm_publish_time":1443073823498,"dist-tags":{"latest":"3.0.0"}}