{"id":24431781,"url":"https://github.com/silentcicero/ethjs-extras","last_synced_at":"2025-04-12T13:21:27.787Z","repository":{"id":63254184,"uuid":"123004700","full_name":"SilentCicero/ethjs-extras","owner":"SilentCicero","description":"All your dApp / App essentials for working with Ethereum.","archived":false,"fork":false,"pushed_at":"2022-03-09T21:46:55.000Z","size":5439,"stargazers_count":18,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-01T17:11:34.134Z","etag":null,"topics":["ethereum","ethjs","replacement","solidity","web3"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SilentCicero.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-26T17:33:31.000Z","updated_at":"2022-04-15T14:03:20.000Z","dependencies_parsed_at":"2022-11-15T21:31:37.374Z","dependency_job_id":null,"html_url":"https://github.com/SilentCicero/ethjs-extras","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SilentCicero%2Fethjs-extras","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SilentCicero%2Fethjs-extras/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SilentCicero%2Fethjs-extras/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SilentCicero%2Fethjs-extras/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SilentCicero","download_url":"https://codeload.github.com/SilentCicero/ethjs-extras/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571837,"owners_count":21126522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethereum","ethjs","replacement","solidity","web3"],"created_at":"2025-01-20T15:21:53.740Z","updated_at":"2025-04-12T13:21:27.760Z","avatar_url":"https://github.com/SilentCicero.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ethjs-extras\n\n\u003cbr /\u003e\n\nNice lightweight extras for building dApps and focused Ethereum arch.\n\n[Do not use in production... yet ;)]\n\n## Install\n\n```\nnpm install --save ethjs-extras\n```\n\n## Usage\n\n```js\nconst {\n  Eth,\n  EthContract,\n  onAccount,\n  onReceipt,\n  onBlock,\n  call,\n} = require('ethjs-extras'); // or import..\n\n// make a raw method call to a rpc network\nEth({ network: 'rinkeby' }).raw('eth_blockNumber').then(console.log).catch(console.log);\n\n// setup a light contract object, use solidity spec and or abi spec.\nconst simpleStore = new EthContract({\n  network: 'rinkeby',\n  address: '0x01a528451419d562a6752318a6fb71898fa5d840',\n  methods: [\n    'SimpleStore(address _master)',\n    'set()',\n    'Set(uint256 _value)',\n    'master():(address)',\n    'get():(uint256)',\n  ],\n});\n\n// contract methods, promise only\nsimpleStore.get().then(console.log).catch(console.log); // using shorthand notation\nsimpleStore.master.call().then(console.log).catch(console.log); // using .call() notation\nsimpleStore.onEvent(console.log); // polls for events, receives, decodes and fires callback\nsimpleStore.getLogs({ fromBlock: 0 }).then(console.log).catch(console.log);\n\n// send transaction notation .sendTransaction\n// simpleStore.set.sendTransaction({ gas: 300000 }).then(console.log).catch(console.log);\n\n// this fires when receipt is available for transaction hash\nonReceipt('0x5005c4dddca407a46b4193379102228cbafc5fb48a269e973d85fd4c30704653', {\n  network: 'mainnet',\n})\n.then(console.log).catch(console.log);\n\n// just call a single contract method\ncall({\n  network: 'rinkeby',\n  address: '0x01a528451419d562a6752318a6fb71898fa5d840',\n  solidity: 'get():(uint256)',\n  args: [],\n}).then(console.log).catch(console.log);\n\n// get the balance\nbalanceOf('0x01a528451419d562a6752318a6fb71898fa5d840', { network: 'rinkeby' })\n.then(console.log)\n.catch(console.log);\n\n// callback fires when accounts loaded from provider\nonAccount(console.log, {\n  provider: window.web3.currentProvider,\n});\n\n// callback fires when new block happens\nonBlock(console.log, {\n  network: 'ropsten',\n});\n```\n\n## Contract Deployment\n\n```js\nconst { Eth } = require('ethjs-extras');\n\n// setup an Eth object\nconst { sendTransaction, onReceipt } = Eth({ provider: window.web3.currentProvider });\n\n// or just use call with the constructor method.. hehe\nsendTransaction({\n  solidity: 'SimpleStore(address _master)',\n  args: ['0x..SOME..ADDRESS..'],\n  data: '0x..CONTRACT..DATA..',\n  construct: true, // will create constructor sig.\n})\n.then(txHash =\u003e onReceipt(txHash))\n.then(receipt =\u003e console.log(receipt.contractAddress))\n.catch(console.log);\n\n// once you have the address, you can setup a contract object, see first example..\n```\n\n## About\n\nExperimental extras for EthJS.\n\n## Philosophy\n\nSimple. To the point. No bullshit. Virtually stateless objects and methods to interact with Ethereum.\n\n## Promise / Callbacks\n\nPromise only unless it's a callback that fires multiple times (i.e. `onBlock`, `onAccount`, `onEvent`)\n\n## Polling =\u003e Websockets\n\nWe are currently using polling for the `receipts` / `logs`.. This will be `websockets` soon.\n\n## Method Design\n\nAll methods can be used individually, or with defaults using the `Eth` object.\n\n## ABI Encoding\n\nDefine in Solidity (thanks to solidity-to-abi), and `Ethers.js` does the rest ;)\n\n## Solidity Types\n\nRemember to define the full type for the solidity method inputs/ouputs (no shortcuts):\n\n```\nBad:\nuint\n\nGood:\nuint256\n\n-----\n\nBad:\nget():(uint)\n\nGood:\nget():(uint256)\n```\n\n## Eth Object\n\nThe Eth object is simply defining defaults which are being passed on to the methods...\n\n```js\nconst { balanceOf, onAccount, contract, call } = Eth({ network: 'rinkeby' });\n```\n\n## Making Raw RPC Calls\n\nYou can make nice and raw RPC calls, but you have to do the hex decoding...\n\n```js\nconst { Eth, hexToBN } = require('ethjs-extras');\n\nEth({ network: 'mainnet' }).raw('eth_blockNumber')\n.then(blockAsHex =\u003e hexToBN(blockAsHex).toString(10)) // now.. BN object\n.catch(console.log);\n```\n\nRaw method API:\n`Eth(...).raw( RPC_METHOD_NAME_STRING, arg1, arg2, arg3 )`\n\nWe provide some helpers `val =\u003e result`..\n\nDecoding Hex:\n`hexToBN` : turn hex numbers into BN.js number object\n\nEncoding Hex:\n`hexPrefix` : hex prefix string data\n`stripHexPrefix` : string hex prefix from string data (if any)\n`hexNum` : always turn value (string / number / BN object) into hex string number\n\n## Call Method Naming\n\nThe `call` and `ethCall` method are the same. Sometimes, function names like `call` are reserved depending on your linter. So we provide both for your convenience.\n\n## Send Transaction\n\nThe `sendTransaction` method is simply the `call` method with the `method` defined as `sendTransaction`.\n\n## Handling Ethereum Units\n\nSee `ethjs-unit` for handling unit conversion (eth =\u003e wei, USD =\u003e eth etc..)\n\n## Network Determination\n\nIf 'network' specified: use infura at valid network (rinkeby, mainnet, ropsten)\nIf 'provider' specified: use provider object\nIf 'eth' specified: use eth object for sendAsync and method calls\n\n## Exported methods\n\n```\nEthRPC,\nonBlock,\nonAccount,\nonReceipt,\nHttpProvider,\nkeccak256,\nEth,\nbalanceOf,\nsolToABI,\nencodeParams,\ndecodeParams,\nethCall,\ncall,\nEthContract,\nencodeSignature,\nencodeMethod,\ndecodeMethod,\nlogDecoder,\nhexNum,\nhexToBN,\nhexPrefix,\nstripHexPrefix,\nBN,\nraw,\nsendTransaction,\nempty,\nsolToABI,\nnumToBN,\n```\n\n## Contributing\n\nPlease help better the ecosystem by submitting issues and pull requests to `ethjs-format`. We need all the help we can get to build the absolute best linting standards and utilities. We follow the AirBNB linting standard and the unix philosophy.\n\n## Help out\n\nThere is always a lot of work to do, and will have many rules to maintain. So please help out in any way that you can:\n\n- Create, enhance, and debug ethjs rules (see our guide to [\"Working on rules\"](./github/CONTRIBUTING.md)).\n- Improve documentation.\n- Chime in on any open issue or pull request.\n- Open new issues about your ideas for making `ethjs-format` better, and pull requests to show us how your idea works.\n- Add new tests to *absolutely anything*.\n- Create or contribute to ecosystem tools, like modules for encoding or contracts.\n- Spread the word.\n\nPlease consult our [Code of Conduct](CODE_OF_CONDUCT.md) docs before helping out.\n\nWe communicate via [issues](https://github.com/ethjs/ethjs-extras/issues) and [pull requests](https://github.com/ethjs/ethjs-extras/pulls).\n\n## Important documents\n\n- [Changelog](CHANGELOG.md)\n- [Code of Conduct](CODE_OF_CONDUCT.md)\n- [License](https://raw.githubusercontent.com/ethjs/ethjs-extras/master/LICENSE)\n\n## Licence\n\nThis project is licensed under the MIT license, Copyright (c) 2018 Nick Dodson. For more information see LICENSE.md.\n\n```\nThe MIT License\n\nCopyright (c) 2018 Nick Dodson. nickdodson.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilentcicero%2Fethjs-extras","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsilentcicero%2Fethjs-extras","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilentcicero%2Fethjs-extras/lists"}