├── .editorconfig ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── build.yml │ └── stale.yml ├── .gitignore ├── .jshintignore ├── .jshintrc ├── .npmignore ├── .nvmrc ├── CHANGELOG.md ├── CONTRIBUTIONS.md ├── LICENSE ├── README.md ├── RELEASE.md ├── REVIEW.md ├── TESTING.md ├── assets └── logo │ ├── web3js.ai │ ├── web3js.jpg │ └── web3js.svg ├── bundle_example.js ├── dist ├── web3.min.js └── web3.min.js.map ├── docs ├── Makefile ├── callbacks-promises-events.rst ├── conf.py ├── getting-started.rst ├── glossary.rst ├── include_package-core.rst ├── include_package-net.rst ├── index.rst ├── make.bat ├── web3-bzz.rst ├── web3-eth-abi.rst ├── web3-eth-accounts.rst ├── web3-eth-contract.rst ├── web3-eth-ens.rst ├── web3-eth-iban.rst ├── web3-eth-net.rst ├── web3-eth-personal.rst ├── web3-eth-subscribe.rst ├── web3-eth.rst ├── web3-net.rst ├── web3-shh.rst ├── web3-utils.rst └── web3.rst ├── karma.conf.js ├── lerna.json ├── package-lock.json ├── package.json ├── packages ├── web3-bzz │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── bzz-test.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-core-helpers │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── errors.js │ │ ├── formatters.js │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ ├── errors-test.ts │ │ └── formatters-test.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-core-method │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-core-promievent │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ └── tsconfig.json ├── web3-core-requestmanager │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── batch.js │ │ ├── givenProvider.js │ │ ├── index.js │ │ └── jsonrpc.js │ └── tsconfig.json ├── web3-core-subscriptions │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── index.js │ │ └── subscription.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── subscriptions.tests.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-core │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── extend.js │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-eth-abi │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── abi-coder-test.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-eth-accounts │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── accounts-tests.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-eth-contract │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── contract-test.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-eth-ens │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── ENS.js │ │ ├── config.js │ │ ├── contracts │ │ │ └── Registry.js │ │ ├── index.js │ │ ├── lib │ │ │ ├── ResolverMethodHandler.js │ │ │ └── contentHash.js │ │ └── resources │ │ │ └── ABI │ │ │ ├── Registry.js │ │ │ └── Resolver.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── ens-test.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-eth-iban │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── iban-tests.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-eth-personal │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── personal-tests.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-eth │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── getNetworkType.js │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── eth.tests.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-eth2-beaconchain │ ├── .babelrc │ ├── Makefile │ ├── babel.config.js │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── index.ts │ │ └── schema.ts │ ├── test │ │ ├── constructor.test.ts │ │ └── schemaMethods.test.ts │ ├── tsconfig.json │ ├── tslint.json │ └── types.ts ├── web3-eth2-core │ ├── .babelrc │ ├── babel.config.json │ ├── jest.config.js │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.ts │ ├── test │ │ ├── constructor.test.ts │ │ └── routeBuild.test.ts │ ├── tsconfig.json │ ├── tslint.json │ └── types.ts ├── web3-net │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── network-test.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-providers-http │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── web3-provider-http-tests.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-providers-ipc │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── web3-provider-ipc-tests.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-providers-ws │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── helpers.js │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── web3-provider-ws-tests.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-shh │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ └── shh-test.ts │ │ ├── tsconfig.json │ │ └── tslint.json ├── web3-utils │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── index.js │ │ ├── soliditySha3.js │ │ └── utils.js │ ├── tsconfig.json │ └── types │ │ ├── index.d.ts │ │ ├── tests │ │ ├── ascii-to-hex-test.ts │ │ ├── bytes-to-hex-test.ts │ │ ├── check-address-checksum-test.ts │ │ ├── encode-packed.ts │ │ ├── from-ascii-test.ts │ │ ├── from-decimal-test.ts │ │ ├── from-utf8-test.ts │ │ ├── from-wei-test.ts │ │ ├── get-signature-params-test.ts │ │ ├── get-unit-value-test.ts │ │ ├── hex-to-ascii-test.ts │ │ ├── hex-to-bytes-test.ts │ │ ├── hex-to-number-string-test.ts │ │ ├── hex-to-number-test.ts │ │ ├── hex-to-string-test.ts │ │ ├── hex-to-utf8-test.ts │ │ ├── is-address-test.ts │ │ ├── is-big-number-test.ts │ │ ├── is-bloom-test.ts │ │ ├── is-bn-test.ts │ │ ├── is-contract-address-in-bloom.ts │ │ ├── is-hex-strict-test.ts │ │ ├── is-hex-test.ts │ │ ├── is-in-bloom.ts │ │ ├── is-topic-in-bloom.ts │ │ ├── is-topic-test.ts │ │ ├── is-topic.ts │ │ ├── is-user-ethereum-address-in-bloom.ts │ │ ├── json-interface-method-to-string-test.ts │ │ ├── keccak256-test.ts │ │ ├── left-pad-test.ts │ │ ├── number-to-hex-test.ts │ │ ├── pad-left-test.ts │ │ ├── pad-right-test.ts │ │ ├── random-hex-test.ts │ │ ├── right-pad-test.ts │ │ ├── sha3-raw-test.ts │ │ ├── sha3-test.ts │ │ ├── solidity-sha3-raw-test.ts │ │ ├── solidity-sha3-test.ts │ │ ├── string-to-hex-test.ts │ │ ├── strip-hex-prefix-test.ts │ │ ├── test-address-test.ts │ │ ├── test-topic-test.ts │ │ ├── to-ascii-test.ts │ │ ├── to-bn-test.ts │ │ ├── to-check-sum-address-test.ts │ │ ├── to-decimal-test.ts │ │ ├── to-hex-test.ts │ │ ├── to-number-test.ts │ │ ├── to-twos-compement-test.ts │ │ ├── to-utf8-test.ts │ │ ├── to-wei-test.ts │ │ ├── unit-map-test.ts │ │ └── utf8-to-hex-test.ts │ │ ├── tsconfig.json │ │ └── tslint.json └── web3 │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ └── index.js │ ├── tsconfig.json │ └── types │ ├── index.d.ts │ ├── tests │ └── web3-test.ts │ ├── tsconfig.json │ └── tslint.json ├── scripts ├── ci.sh ├── e2e.cdn.sh ├── e2e.chrome.sh ├── e2e.firefox.sh ├── e2e.ganache.core.sh ├── e2e.ganache.sh ├── e2e.geth.automine.sh ├── e2e.geth.instamine.sh ├── e2e.gnosis.dex.sh ├── e2e.min.sh ├── e2e.mosaic.sh ├── e2e.npm.publish.sh ├── e2e.windows.sh ├── eth2.sh ├── html │ └── index.html └── js │ ├── basic_usage.js │ ├── ens.js │ └── resolutions.js ├── test ├── 1_givenProvider-ethereumProvider.js ├── 2_givenProvider-currentProvider.js ├── 3_givenProvider-ganache.js ├── abi.decodeParam-ethjs.js_ ├── abi.decodeParameter.js ├── abi.encodeParam-ethjs.js_ ├── abi.encodeParameter.js ├── async.js ├── batch.js ├── config │ └── ensAddresses.json ├── contract.encodeABI.js ├── contract.errors.js ├── contract.js ├── e2e.contract.deploy.js ├── e2e.contract.events.js ├── e2e.ens.js ├── e2e.method.call.js ├── e2e.method.send.js ├── e2e.method.signing.js ├── e2e.minified.js ├── errors.js ├── eth.Iban.js ├── eth.abi.decodeLog.js ├── eth.abi.decodeParameter.js ├── eth.abi.decodeParameters.js ├── eth.abi.encodeEventSignature.js ├── eth.abi.encodeFunctionCall.js ├── eth.abi.encodeFunctionSignature.js ├── eth.abi.encodeParameter.js ├── eth.abi.encodeParameters.js ├── eth.accounts.create.js ├── eth.accounts.encrypt-decrypt.js ├── eth.accounts.sign.js ├── eth.accounts.signTransaction.js ├── eth.accounts.wallet.js ├── eth.call.js ├── eth.defaultAccount.js ├── eth.defaultBlock.js ├── eth.ens.js ├── eth.estimateGas.js ├── eth.feeHistory.js ├── eth.gasPrice.js ├── eth.getAccounts.js ├── eth.getBalance.js ├── eth.getBlock.js ├── eth.getBlockNumber.js ├── eth.getBlockTransactionCount.js ├── eth.getBlockUncleCount.js ├── eth.getChainId.js ├── eth.getCode.js ├── eth.getCoinbase.js ├── eth.getHashRate.js ├── eth.getNodeVersion.js ├── eth.getPendingTransactions.js ├── eth.getProof.js ├── eth.getStorageAt.js ├── eth.getTransaction.js ├── eth.getTransactionFromBlock.js ├── eth.getTransactionReceipt.js ├── eth.getUncle.js ├── eth.getWork.js ├── eth.handleRevert.js ├── eth.isMining.js ├── eth.maxListenersWarningThreshold.js ├── eth.net.getNetworkType.js ├── eth.net.getPeerCount.js ├── eth.net.isListening.js ├── eth.net_methods.js ├── eth.protocolVersion.js ├── eth.requestAccounts.js ├── eth.sendTransaction.js ├── eth.sendTransaction.revert.js ├── eth.sign.js ├── eth.submitWork.js ├── eth.subscribe.ganache.js ├── eth.subscribe.js ├── eth.transactionBlockTimeout.js ├── eth.transactionConfirmationBlocks.js ├── eth.transactionPollingTimeout.js ├── eth_methods.js ├── event.decode.js ├── event.encode.js ├── extend.js ├── formatters.inputAddressFormatter.js ├── formatters.inputDefaultBlockFormatter.js ├── formatters.inputLogFormatter.js ├── formatters.inputPostFormatter.js ├── formatters.inputTransactionFormatter.js ├── formatters.outputBlockFormatter.js ├── formatters.outputLogFormatter.js ├── formatters.outputPostFormatter.js ├── formatters.outputTransactionFormatter.js ├── formatters.outputTransactionReceiptFormatter.js ├── helpers │ ├── FakeHttpProvider.js │ ├── FakeIpcProvider.js │ ├── FakeIpcProvider2.js │ ├── FakeIpcRequest.js │ ├── FakeXHR2.js │ ├── test.method.js │ ├── test.subscription.js │ └── test.utils.js ├── httpprovider.js ├── iban.createIndirect.js ├── iban.fromAddress.js ├── iban.isValid.js ├── iban.toAddress.js ├── iban.toIban.js ├── ipcprovider.js ├── jsonrpc.id.js ├── jsonrpc.isValidResponse.js ├── jsonrpc.toBatchPayload.js ├── jsonrpc.toPayload.js ├── method.buildCall.js ├── method.extractCallback.js ├── method.formatInput.js ├── method.formatOutput.js ├── method.getCall.js ├── method.validateArgs.js ├── mocha.opts ├── personal.getAccounts.js ├── personal.lockAccount.js ├── personal.newAccount.js ├── personal.sendTransaction.js ├── personal.unlockAccount.js ├── personal_methods.js ├── provider.js ├── requestmanager.js ├── setProvider.js ├── shh.post.js ├── shh.subscribe.js ├── shh_methods.js ├── sources │ ├── Basic.json │ ├── Basic.sol │ ├── Child.json │ ├── Misc.json │ ├── Misc.sol │ ├── Parent.json │ ├── ParentAndChild.sol │ ├── Reverts.json │ └── Reverts.sol ├── utils.compareBlockNumbers.js ├── utils.encodePacked.js ├── utils.fromAscii.js ├── utils.fromNumber.js ├── utils.fromWei.js ├── utils.hexToNumber.js ├── utils.isAddress.js ├── utils.isBN.js ├── utils.isChecksumAddress.js ├── utils.isHex.js ├── utils.isHexStrict.js ├── utils.randomHex.js ├── utils.sha3.js ├── utils.sha3Raw.js ├── utils.soliditySha3.js ├── utils.soliditySha3Raw.js ├── utils.stripHexPrefix.js ├── utils.toAscii.js ├── utils.toBigNumber.js ├── utils.toHex.js ├── utils.toNumber.js ├── utils.toNumberString.js ├── utils.toTwosComplement.js ├── utils.toUtf8.js ├── utils.toWei.js ├── utils.utf8ToHex.js ├── utils_methods.js ├── web3_methods.js └── websocket.ganache.js ├── tsconfig.json ├── verdaccio.yml └── webpack.config.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | #### Expected behavior 12 | 13 | #### Actual behavior 14 | 15 | #### Steps to reproduce the behavior 16 | 17 | 1. [First step] 18 | 2. [Second step] 19 | 3. [and so on...] 20 | 21 | #### Logs 22 | 23 | 24 | 25 | #### Environment 26 | 27 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: "Close stale issues" 2 | on: 3 | schedule: 4 | - cron: "0 0 * * *" 5 | 6 | jobs: 7 | stale: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/stale@v3 11 | with: 12 | repo-token: ${{ secrets.GITHUB_TOKEN }} 13 | stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.' 14 | stale-pr-message: 'This PR has been automatically marked as stale beacause it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.' 15 | days-before-stale: 60 16 | days-before-close: 14 17 | operations-per-run: 100 18 | exempt-pr-labels: 'work-in-progress' 19 | exempt-issue-labels: 'work-in-progress' 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | */**/*un~ 4 | *un~ 5 | */**/.DS_Store 6 | npm-debug.log 7 | .npm/ 8 | /coverage 9 | /tmp 10 | node_modules 11 | .idea/ 12 | .npm/ 13 | .history/ 14 | .vscode/ 15 | packages/web3/dist/ 16 | lerna-debug.log 17 | .nyc_output/ 18 | build/ 19 | contracts/ 20 | migrations/ 21 | truffle-config.js 22 | test/config/ensAddresses.json 23 | */**/lib 24 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | packages/**/node_modules/ 3 | karma.conf.js 4 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "browserify": true, 3 | "bitwise": true, 4 | "camelcase": true, 5 | "eqeqeq": true, 6 | "esversion": 8, 7 | "freeze": true, 8 | "funcscope": false, 9 | "maxcomplexity": 15, 10 | "maxdepth": 4, 11 | "maxerr": 50, 12 | /*"maxlen": 80*/ /*this should be our goal*/ 13 | /*"maxparams": 3,*/ 14 | "nonew": true, 15 | "unused": true, 16 | "undef": true, 17 | "predef": [ 18 | "console" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.idea 2 | test 3 | dist 4 | docs 5 | coverage 6 | scripts 7 | .gitignore 8 | .editorconfig 9 | .npmignore 10 | .DS_Store 11 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v14.15.1 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This file is part of web3.js. 2 | 3 | web3.js is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | web3.js is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Lesser General Public License for more details. 12 | 13 | You should have received a copy of the GNU Lesser General Public License 14 | along with web3.js. If not, see . 15 | -------------------------------------------------------------------------------- /assets/logo/web3js.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/node-real/js-direct-route/a9c87316ecc413d2c5a57c3c673e25bf5e7bb295/assets/logo/web3js.ai -------------------------------------------------------------------------------- /assets/logo/web3js.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/node-real/js-direct-route/a9c87316ecc413d2c5a57c3c673e25bf5e7bb295/assets/logo/web3js.jpg -------------------------------------------------------------------------------- /docs/getting-started.rst: -------------------------------------------------------------------------------- 1 | 2 | =============== 3 | Getting Started 4 | =============== 5 | 6 | The web3.js library is a collection of modules that contain functionality for the ethereum ecosystem. 7 | 8 | - ``web3-eth`` is for the ethereum blockchain and smart contracts. 9 | - ``web3-shh`` is for the whisper protocol, to communicate p2p and broadcast. 10 | - ``web3-bzz`` is for the swarm protocol, the decentralized file storage. 11 | - ``web3-utils`` contains useful helper functions for Dapp developers. 12 | 13 | 14 | .. _adding-web3: 15 | 16 | Adding web3.js 17 | ============== 18 | 19 | .. index:: npm 20 | .. index:: yarn 21 | 22 | First you need to get web3.js into your project. This can be done using the following methods: 23 | 24 | - npm: ``npm install web3`` 25 | - yarn: ``yarn add web3`` 26 | - pure js: link the ``dist/web3.min.js`` 27 | 28 | After that you need to create a web3 instance and set a provider. 29 | 30 | Most Ethereum-supported browsers like MetaMask have an `EIP-1193 `_ compliant provider available at ``window.ethereum``. 31 | 32 | For web3.js, check ``Web3.givenProvider``. 33 | 34 | If this property is ``null`` you should connect to a remote/local node. 35 | 36 | .. code-block:: javascript 37 | 38 | // In Node.js use: const Web3 = require('web3'); 39 | 40 | const web3 = new Web3(Web3.givenProvider || "ws://localhost:8545"); 41 | 42 | That's it! now you can use the ``web3`` object. 43 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | 2 | ================================= 3 | web3.js - Ethereum JavaScript API 4 | ================================= 5 | 6 | web3.js is a collection of libraries that allow you to interact with a local or remote ethereum node using HTTP, IPC or WebSocket. 7 | 8 | The following documentation will guide you through :ref:`installing and running web3.js ` as well as providing an :ref:`API reference documentation <#id1>` with examples. 9 | 10 | Contents: 11 | 12 | :ref:`Keyword Index `, :ref:`Search Page ` 13 | 14 | .. toctree:: 15 | :maxdepth: 2 16 | :caption: User Documentation 17 | 18 | getting-started 19 | callbacks-promises-events 20 | glossary 21 | 22 | 23 | .. toctree:: 24 | :maxdepth: 2 25 | :caption: API Reference 26 | 27 | web3 28 | web3-eth 29 | web3-eth-subscribe 30 | web3-eth-contract 31 | web3-eth-accounts 32 | web3-eth-personal 33 | web3-eth-ens 34 | web3-eth-iban 35 | web3-eth-abi 36 | web3-net 37 | web3-bzz 38 | web3-shh 39 | web3-utils 40 | web3-admin 41 | 42 | 43 | Special thanks to `Netlify `_ for providing build and deploy services for our end-to-end integration tests. -------------------------------------------------------------------------------- /docs/web3-eth-net.rst: -------------------------------------------------------------------------------- 1 | .. _eth-net: 2 | 3 | ========= 4 | web3.eth.net 5 | ========= 6 | 7 | 8 | Contains functions to get information about the current network. 9 | 10 | 11 | ------------------------------------------------------------------------------ 12 | 13 | 14 | .. include:: include_package-net.rst 15 | 16 | 17 | ------------------------------------------------------------------------------ 18 | 19 | getNetworkType 20 | ===================== 21 | 22 | .. code-block:: javascript 23 | 24 | web3.eth.net.getNetworkType([callback]) 25 | 26 | Guesses the chain the node is connected by comparing the genesis hashes. 27 | 28 | .. note:: It's recommended to use the :ref:`web3.eth.getChainId ` method to detect the currently connected chain. 29 | 30 | ------- 31 | Returns 32 | ------- 33 | 34 | ``Promise`` returns ``String``: 35 | - ``"main"`` for main network 36 | - ``"morden"`` for the morden test network 37 | - ``"ropsten"`` for the morden test network 38 | - ``"private"`` for undetectable networks. 39 | 40 | 41 | ------- 42 | Example 43 | ------- 44 | 45 | .. code-block:: javascript 46 | 47 | web3.eth.net.getNetworkType() 48 | .then(console.log); 49 | > "main" 50 | 51 | 52 | -------------------------------------------------------------------------------- /docs/web3-net.rst: -------------------------------------------------------------------------------- 1 | .. _net: 2 | 3 | ======== 4 | web3.*.net 5 | ======== 6 | 7 | 8 | The ``web3-net`` package allows you to interact with an Ethereum node's network properties. 9 | 10 | 11 | .. code-block:: javascript 12 | 13 | var Net = require('web3-net'); 14 | 15 | // "Personal.providers.givenProvider" will be set if in an Ethereum supported browser. 16 | var net = new Net(Net.givenProvider || 'ws://some.local-or-remote.node:8546'); 17 | 18 | 19 | // or using the web3 umbrella package 20 | 21 | var Web3 = require('web3'); 22 | var web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546'); 23 | 24 | // -> web3.eth.net 25 | // -> web3.bzz.net 26 | // -> web3.shh.net 27 | 28 | 29 | 30 | ------------------------------------------------------------------------------ 31 | 32 | 33 | .. include:: include_package-net.rst 34 | 35 | 36 | ------------------------------------------------------------------------------ 37 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.8", 3 | "lerna": "2.0.0", 4 | "command": { 5 | "init": { 6 | "exact": true 7 | }, 8 | "publish": { 9 | "exact": true, 10 | "skipGit": true 11 | } 12 | }, 13 | "packages": [ 14 | "packages/*" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /packages/web3-bzz/README.md: -------------------------------------------------------------------------------- 1 | # web3-bzz 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is a sub-package of [web3.js][repo]. 6 | 7 | This is the swarm package. 8 | 9 | Please read the [documentation][docs] for more. 10 | 11 | ## Installation 12 | 13 | ### Node.js 14 | 15 | ```bash 16 | npm install web3-bzz 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | const Web3Bzz = require('web3-bzz'); 23 | 24 | const bzz = new Web3Bzz('http://swarm-gateways.net'); 25 | ``` 26 | 27 | ## Types 28 | 29 | All the TypeScript typings are placed in the `types` folder. 30 | 31 | [docs]: http://web3js.readthedocs.io/en/1.0/ 32 | [repo]: https://github.com/ethereum/web3.js 33 | [npm-image]: https://img.shields.io/npm/v/web3-bzz.svg 34 | [npm-url]: https://npmjs.org/package/web3-bzz 35 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-bzz 36 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-bzz 37 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-bzz 38 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-bzz 39 | -------------------------------------------------------------------------------- /packages/web3-bzz/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-bzz", 3 | "version": "1.0.7", 4 | "description": "Web3 module to interact with the Swarm network.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-bzz", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "publishConfig": { 11 | "access": "public" 12 | }, 13 | "types": "types/index.d.ts", 14 | "scripts": { 15 | "compile": "tsc -b tsconfig.json", 16 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types", 17 | "postinstall": "echo \"WARNING: the web3-bzz api will be deprecated in the next version\"" 18 | }, 19 | "main": "lib/index.js", 20 | "dependencies": { 21 | "@types/node": "^12.12.6", 22 | "got": "9.6.0", 23 | "swarm-js": "^0.1.40" 24 | }, 25 | "devDependencies": { 26 | "dtslint": "^3.4.1", 27 | "typescript": "^3.9.5" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/web3-bzz/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-bzz/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | web3.js is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | web3.js is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU Lesser General Public License for more details. 11 | You should have received a copy of the GNU Lesser General Public License 12 | along with web3.js. If not, see . 13 | */ 14 | /** 15 | * @file index.d.ts 16 | * @author Josh Stevens 17 | * @date 2018 18 | */ 19 | 20 | export class Bzz { 21 | constructor(); 22 | constructor(provider: any); 23 | 24 | readonly givenProvider: any; 25 | static readonly givenProvider: any; 26 | readonly currentProvider: any; 27 | setProvider(provider: any): boolean; 28 | 29 | upload(data: any): Promise; 30 | 31 | download(bzzHash: string, localPath?: string): Promise; 32 | 33 | pick: Pick; 34 | } 35 | 36 | export interface Pick { 37 | file: () => Promise; 38 | directory: () => Promise; 39 | data: () => Promise; 40 | } 41 | -------------------------------------------------------------------------------- /packages/web3-bzz/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-bzz": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-bzz/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "unified-signatures": false, 10 | "no-redundant-jsdoc": false 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/web3-core-helpers/README.md: -------------------------------------------------------------------------------- 1 | # web3-core-helpers 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is a sub-package of [web3.js][repo] with useful helper functions. 6 | 7 | Please read the [documentation][docs] for more. 8 | 9 | ## Installation 10 | 11 | ### Node.js 12 | 13 | ```bash 14 | npm install web3-core-helpers 15 | ``` 16 | 17 | ## Usage 18 | 19 | ```js 20 | const helpers = require('web3-core-helpers'); 21 | 22 | helpers.formatters; 23 | helpers.errors; 24 | ... 25 | ``` 26 | 27 | ## Types 28 | 29 | All the TypeScript typings are placed in the `types` folder. 30 | 31 | [docs]: http://web3js.readthedocs.io/en/1.0/ 32 | [repo]: https://github.com/ethereum/web3.js 33 | [npm-image]: https://img.shields.io/npm/v/web3-core-helpers.svg 34 | [npm-url]: https://npmjs.org/package/web3-core-helpers 35 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-core-helpers 36 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-core-helpers 37 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-core-helpers 38 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-core-helpers -------------------------------------------------------------------------------- /packages/web3-core-helpers/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-core-helpers", 3 | "version": "1.0.7", 4 | "description": "Web3 core tools helper for sub packages. This is an internal package.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-helpers", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "web3-eth-iban": "1.5.1", 21 | "web3-utils": "1.5.1" 22 | }, 23 | "devDependencies": { 24 | "@types/node": "^12.12.6", 25 | "dtslint": "^3.4.1", 26 | "typescript": "^3.9.5" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/web3-core-helpers/src/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file index.js 19 | * @author Fabian Vogelsteller 20 | * @date 2017 21 | */ 22 | 23 | "use strict"; 24 | 25 | var errors = require('./errors'); 26 | var formatters = require('./formatters'); 27 | 28 | module.exports = { 29 | errors: errors, 30 | formatters: formatters 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /packages/web3-core-helpers/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-core-helpers/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-core-helpers": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-core-helpers/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/web3-core-method/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-core-method", 3 | "version": "1.0.7", 4 | "description": "Creates the methods on the web3 modules. This is an internal package.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-method", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "main": "lib/index.js", 16 | "dependencies": { 17 | "@ethereumjs/common": "^2.4.0", 18 | "@ethersproject/transactions": "^5.0.0-beta.135", 19 | "web3-core-helpers": "1.5.1", 20 | "web3-core-promievent": "1.5.1", 21 | "web3-core-subscriptions": "1.5.1", 22 | "web3-utils": "1.5.1" 23 | }, 24 | "publishConfig": { 25 | "access": "public" 26 | }, 27 | "devDependencies": { 28 | "dtslint": "^3.4.1", 29 | "typescript": "^3.9.5" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/web3-core-method/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib", 5 | "esModuleInterop": true 6 | }, 7 | "include": [ 8 | "./src" 9 | ] 10 | } -------------------------------------------------------------------------------- /packages/web3-core-method/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | web3.js is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | web3.js is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU Lesser General Public License for more details. 11 | You should have received a copy of the GNU Lesser General Public License 12 | along with web3.js. If not, see . 13 | */ 14 | /** 15 | * @file index.d.ts 16 | * @author Samuel Furter 17 | * @date 2018 18 | */ 19 | 20 | import {JsonRpcPayload} from 'web3-core-helpers'; 21 | 22 | export interface Method { 23 | name: string; 24 | call: string; 25 | params?: number; 26 | inputFormatter?: Array<(() => void) | null>; 27 | outputFormatter?: () => void; 28 | transformPayload?: () => void; 29 | extraFormatters?: any; 30 | defaultBlock?: string; 31 | defaultAccount?: string | null; 32 | abiCoder?: any; 33 | handleRevert?: boolean; 34 | } 35 | -------------------------------------------------------------------------------- /packages/web3-core-method/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-core-method": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-core-method/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/web3-core-promievent/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-core-promievent", 3 | "version": "1.0.7", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "eventemitter3": { 8 | "version": "4.0.4", 9 | "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.4.tgz", 10 | "integrity": "sha512-rlaVLnVxtxvoyLsQQFBx53YmXHDxRIzzTLbdfxqi4yocpSjAxXwkU0cScM5JgSKMqEhrZpnvQ2D9gjylR0AimQ==" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/web3-core-promievent/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-core-promievent", 3 | "version": "1.0.7", 4 | "description": "This package extends the EventEmitter with the Promise class to allow chaining as well as multiple final states of a function.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-promievent", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "main": "lib/index.js", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json" 13 | }, 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "dependencies": { 18 | "eventemitter3": "4.0.4" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/web3-core-promievent/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-core-requestmanager/README.md: -------------------------------------------------------------------------------- 1 | # web3-core-requestmanager 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is a sub-package of [web3.js][repo]. 6 | 7 | This requestmanager package is used by most [web3.js][repo] packages. 8 | 9 | Please read the [documentation][docs] for more. 10 | 11 | ## Installation 12 | 13 | ### Node.js 14 | 15 | ```bash 16 | npm install web3-core-requestmanager 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | const Web3WsProvider = require('web3-providers-ws'); 23 | const Web3RequestManager = require('web3-core-requestmanager'); 24 | 25 | const requestManager = new Web3RequestManager(new Web3WsProvider('ws://localhost:8546')); 26 | ``` 27 | 28 | [docs]: http://web3js.readthedocs.io/en/1.0/ 29 | [repo]: https://github.com/ethereum/web3.js 30 | [npm-image]: https://img.shields.io/npm/v/web3-core-requestmanager.svg 31 | [npm-url]: https://npmjs.org/package/web3-core-requestmanager 32 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-core-requestmanager 33 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-core-requestmanager 34 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-core-requestmanager 35 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-core-requestmanager 36 | 37 | -------------------------------------------------------------------------------- /packages/web3-core-requestmanager/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-core-requestmanager", 3 | "version": "1.0.8", 4 | "description": "Web3 module to handle requests to external providers.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-requestmanager", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "main": "lib/index.js", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json" 13 | }, 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "dependencies": { 18 | "@node-real/web3-core-helpers": "1.0.7", 19 | "util": "^0.12.0", 20 | "web3-providers-http": "1.5.1", 21 | "web3-providers-ipc": "1.5.1", 22 | "web3-providers-ws": "1.5.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/web3-core-requestmanager/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-core-subscriptions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-core-subscriptions", 3 | "version": "1.0.7", 4 | "description": "Manages web3 subscriptions. This is an internal package.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-subscriptions", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "main": "lib/index.js", 16 | "dependencies": { 17 | "eventemitter3": "4.0.4", 18 | "web3-core-helpers": "1.5.1" 19 | }, 20 | "publishConfig": { 21 | "access": "public" 22 | }, 23 | "devDependencies": { 24 | "dtslint": "^3.4.1", 25 | "typescript": "^3.9.5" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/web3-core-subscriptions/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-core-subscriptions/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-core-subscriptions": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-core-subscriptions/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "unified-signatures": false, 10 | "no-redundant-jsdoc": false 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/web3-core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-core", 3 | "version": "1.0.8", 4 | "description": "Web3 core tools for sub-packages. This is an internal package.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "@node-real/web3-core-helpers": "1.0.7", 21 | "@node-real/web3-core-method": "latest", 22 | "@node-real/web3-core-requestmanager": "1.0.8", 23 | "@types/bn.js": "^4.11.5", 24 | "@types/node": "^12.12.6", 25 | "bignumber.js": "^9.0.0", 26 | "web3-utils": "1.5.1" 27 | }, 28 | "devDependencies": { 29 | "dtslint": "^3.4.1", 30 | "typescript": "^3.9.5" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/web3-core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-core/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-core": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-core/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "unified-signatures": false, 10 | "no-redundant-jsdoc": false 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/web3-eth-abi/README.md: -------------------------------------------------------------------------------- 1 | # web3-eth-abi 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is a sub-package of [web3.js][repo]. 6 | 7 | This is the abi package used in the `web3-eth` package. 8 | 9 | Please read the [documentation][docs] for more. 10 | 11 | ## Installation 12 | 13 | ### Node.js 14 | 15 | ```bash 16 | npm install web3-eth-abi 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | const Web3EthAbi = require('web3-eth-abi'); 23 | 24 | Web3EthAbi.encodeFunctionSignature('myMethod(uint256,string)'); 25 | > '0x24ee0097' 26 | ``` 27 | 28 | ## Types 29 | 30 | All the TypeScript typings are placed in the `types` folder. 31 | 32 | [docs]: http://web3js.readthedocs.io/en/1.0/ 33 | [repo]: https://github.com/ethereum/web3.js 34 | [npm-image]: https://img.shields.io/npm/v/web3-eth-abi.svg 35 | [npm-url]: https://npmjs.org/package/web3-eth-abi 36 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-eth-abi 37 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-eth-abi 38 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-eth-abi 39 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-eth-abi 40 | -------------------------------------------------------------------------------- /packages/web3-eth-abi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-eth-abi", 3 | "version": "1.0.7", 4 | "description": "Web3 module encode and decode EVM in/output.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth-abi", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "main": "lib/index.js", 16 | "dependencies": { 17 | "@ethersproject/abi": "5.0.7", 18 | "web3-utils": "1.5.1" 19 | }, 20 | "publishConfig": { 21 | "access": "public" 22 | }, 23 | "devDependencies": { 24 | "dtslint": "^3.4.1", 25 | "typescript": "^3.9.5" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/web3-eth-abi/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ], 9 | } -------------------------------------------------------------------------------- /packages/web3-eth-abi/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-eth-abi": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-eth-abi/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "typedef-whitespace": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/web3-eth-accounts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-eth-accounts", 3 | "version": "1.0.8", 4 | "description": "Web3 module to generate Ethereum accounts and sign data and transactions.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth-accounts", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "@ethereumjs/common": "^2.3.0", 21 | "@ethereumjs/tx": "^3.2.1", 22 | "@node-real/web3-core-method": "latest", 23 | "crypto-browserify": "3.12.0", 24 | "eth-lib": "0.2.8", 25 | "ethereumjs-util": "^7.0.10", 26 | "scrypt-js": "^3.0.1", 27 | "uuid": "3.3.2", 28 | "web3-core": "1.5.1", 29 | "web3-core-helpers": "1.5.1", 30 | "web3-utils": "1.5.1" 31 | }, 32 | "devDependencies": { 33 | "dtslint": "^3.4.1", 34 | "typescript": "^3.9.5" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/web3-eth-accounts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib", 5 | "esModuleInterop": true 6 | }, 7 | "include": [ 8 | "./src" 9 | ] 10 | } -------------------------------------------------------------------------------- /packages/web3-eth-accounts/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | web3.js is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | web3.js is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU Lesser General Public License for more details. 11 | You should have received a copy of the GNU Lesser General Public License 12 | along with web3.js. If not, see . 13 | */ 14 | /** 15 | * @file index.d.ts 16 | * @author Josh Stevens , Samuel Furter 17 | * @date 2018 18 | */ 19 | 20 | import { AccountsBase, SignedTransaction, WalletBase } from 'web3-core'; 21 | 22 | export {SignedTransaction} from 'web3-core'; 23 | 24 | export class Accounts extends AccountsBase {} 25 | 26 | export class Wallet extends WalletBase {} 27 | 28 | export interface Sign extends SignedTransaction { 29 | message: string; 30 | signature: string; 31 | } 32 | 33 | export interface SignatureObject { 34 | messageHash: string; 35 | r: string; 36 | s: string; 37 | v: string; 38 | } 39 | -------------------------------------------------------------------------------- /packages/web3-eth-accounts/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-eth-accounts": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-eth-accounts/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/web3-eth-contract/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-eth-contract", 3 | "version": "1.0.8", 4 | "description": "Web3 module to interact with Ethereum smart contracts.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth-contract", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "@node-real/web3-core-method": "latest", 21 | "@types/bn.js": "^4.11.5", 22 | "web3-core": "1.5.1", 23 | "web3-core-helpers": "1.5.1", 24 | "web3-core-promievent": "1.5.1", 25 | "web3-core-subscriptions": "1.5.1", 26 | "web3-eth-abi": "1.5.1", 27 | "web3-utils": "1.5.1" 28 | }, 29 | "devDependencies": { 30 | "dtslint": "^3.4.1", 31 | "typescript": "^3.9.5" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/web3-eth-contract/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-eth-contract/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-eth-contract": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-eth-contract/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "no-empty-interface": false, 10 | "unified-signatures": false, 11 | "no-redundant-jsdoc": false 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/web3-eth-ens/README.md: -------------------------------------------------------------------------------- 1 | # web3-eth-ens 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is a sub-package of [web3.js][repo]. 6 | 7 | This is the contract package to be used in the `web3-eth` package. 8 | 9 | Please read the [documentation][docs] for more. 10 | 11 | ## Installation 12 | 13 | ### Node.js 14 | 15 | ```bash 16 | npm install web3-eth-ens 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | const eth = new Web3Eth(web3.currentProvider); 23 | const ens = new EthEns(eth); 24 | 25 | ens.getAddress('ethereum.eth').then(function(result) { 26 | console.log(result); 27 | }); 28 | ``` 29 | 30 | ## Types 31 | 32 | All the TypeScript typings are placed in the `types` folder. 33 | 34 | [docs]: http://web3js.readthedocs.io/en/1.0/ 35 | [repo]: https://github.com/ethereum/web3.js 36 | [npm-image]: https://img.shields.io/npm/v/web3-eth-ens.svg 37 | [npm-url]: https://npmjs.org/package/web3-eth-ens 38 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-eth-ens 39 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-eth-ens 40 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-eth-ens 41 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-eth-ens -------------------------------------------------------------------------------- /packages/web3-eth-ens/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-eth-ens", 3 | "version": "1.0.7", 4 | "description": "ENS support for web3.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth-ens", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "content-hash": "^2.5.2", 21 | "eth-ens-namehash": "2.0.8", 22 | "web3-core": "1.5.1", 23 | "web3-core-helpers": "1.5.1", 24 | "web3-core-promievent": "1.5.1", 25 | "web3-eth-abi": "1.5.1", 26 | "web3-eth-contract": "1.5.1", 27 | "web3-utils": "1.5.1" 28 | }, 29 | "devDependencies": { 30 | "dtslint": "^3.4.1", 31 | "typescript": "^3.9.5", 32 | "web3-eth": "1.5.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/web3-eth-ens/src/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | web3.js is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | web3.js is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU Lesser General Public License for more details. 11 | You should have received a copy of the GNU Lesser General Public License 12 | along with web3.js. If not, see . 13 | */ 14 | /** 15 | * @file index.js 16 | * 17 | * @author Samuel Furter 18 | * @date 2018 19 | */ 20 | 21 | "use strict"; 22 | 23 | var ENS = require('./ENS'); 24 | 25 | module.exports = ENS; 26 | -------------------------------------------------------------------------------- /packages/web3-eth-ens/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-eth-ens/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-eth-ens": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-eth-ens/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "no-empty-interface": false, 10 | "unified-signatures": false 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/web3-eth-iban/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-eth-iban", 3 | "version": "1.0.7", 4 | "description": "This package converts Ethereum addresses to IBAN addresses a vice versa.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth-iban", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "bn.js": "^4.11.9", 21 | "web3-utils": "1.5.1" 22 | }, 23 | "devDependencies": { 24 | "dtslint": "^3.4.1", 25 | "typescript": "^3.9.5" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/web3-eth-iban/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-eth-iban/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-eth-iban": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-eth-iban/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/web3-eth-personal/README.md: -------------------------------------------------------------------------------- 1 | # web3-eth-personal 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is a sub-package of [web3.js][repo]. 6 | 7 | This is the personal package used in the `web3-eth` package. 8 | 9 | Please read the [documentation][docs] for more. 10 | 11 | ## Installation 12 | 13 | ### Node.js 14 | 15 | ```bash 16 | npm install web3-eth-personal 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | const Web3EthPersonal = require('web3-eth-personal'); 23 | 24 | const personal = new Web3EthPersonal('ws://localhost:8546'); 25 | ``` 26 | 27 | ## Types 28 | 29 | All the TypeScript typings are placed in the `types` folder. 30 | 31 | [docs]: http://web3js.readthedocs.io/en/1.0/ 32 | [repo]: https://github.com/ethereum/web3.js 33 | [npm-image]: https://img.shields.io/npm/v/web3-eth-personal.svg 34 | [npm-url]: https://npmjs.org/package/web3-eth-personal 35 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-eth-personal 36 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-eth-personal 37 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-eth-personal 38 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-eth-personal 39 | -------------------------------------------------------------------------------- /packages/web3-eth-personal/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-eth-personal", 3 | "version": "1.0.8", 4 | "description": "Web3 module to interact with the Ethereum blockchain accounts stored in the node.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth-personal", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "@node-real/web3-core-method": "latest", 21 | "@types/node": "^12.12.6", 22 | "web3-core": "1.5.1", 23 | "web3-core-helpers": "1.5.1", 24 | "web3-net": "1.5.1", 25 | "web3-utils": "1.5.1" 26 | }, 27 | "devDependencies": { 28 | "dtslint": "^3.4.1", 29 | "typescript": "^3.9.5" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/web3-eth-personal/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-eth-personal/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-eth-personal": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-eth-personal/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "unified-signatures": false 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/web3-eth/README.md: -------------------------------------------------------------------------------- 1 | # web3-eth 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is a sub-package of [web3.js][repo]. 6 | 7 | This Eth package is used within some [web3.js][repo] packages. 8 | 9 | Please read the [documentation][docs] for more. 10 | 11 | ## Installation 12 | 13 | ### Node.js 14 | 15 | ```bash 16 | npm install web3-eth 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | const Web3Eth = require('web3-eth'); 23 | 24 | const eth = new Web3Eth('ws://localhost:8546'); 25 | ``` 26 | 27 | ## Types 28 | 29 | All the TypeScript typings are placed in the `types` folder. 30 | 31 | [docs]: http://web3js.readthedocs.io/en/1.0/ 32 | [repo]: https://github.com/ethereum/web3-eth.js 33 | [npm-image]: https://img.shields.io/npm/v/web3-eth.svg 34 | [npm-url]: https://npmjs.org/package/web3-eth 35 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-eth 36 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-eth 37 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-eth 38 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-eth 39 | -------------------------------------------------------------------------------- /packages/web3-eth/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-eth", 3 | "version": "1.0.8", 4 | "description": "Web3 module to interact with the Ethereum blockchain and smart contracts.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "@node-real/web3-core": "1.0.8", 21 | "@node-real/web3-core-helpers": "1.0.7", 22 | "@node-real/web3-core-method": "1.0.7", 23 | "web3-core-subscriptions": "1.5.1", 24 | "web3-eth-abi": "1.5.1", 25 | "web3-eth-accounts": "1.5.1", 26 | "web3-eth-contract": "1.5.1", 27 | "web3-eth-ens": "1.5.1", 28 | "web3-eth-iban": "1.5.1", 29 | "web3-eth-personal": "1.5.1", 30 | "web3-net": "1.5.1", 31 | "web3-utils": "1.5.1" 32 | }, 33 | "devDependencies": { 34 | "dtslint": "^3.4.1", 35 | "typescript": "^3.9.5" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/web3-eth/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-eth/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-eth": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-eth/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "unified-signatures": false 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/web3-eth2-beaconchain/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | "@babel/preset-typescript" 5 | ], 6 | "plugins": [ 7 | "@babel/plugin-proposal-class-properties", 8 | "@babel/plugin-transform-runtime" 9 | ] 10 | } -------------------------------------------------------------------------------- /packages/web3-eth2-beaconchain/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: lodestar-docker lighthouse-docker 2 | 3 | lodestar-docker: 4 | docker run --network host chainsafe/lodestar beacon --testnet medalla --api.rest.enabled true 5 | 6 | lighthouse-docker: 7 | docker run -p 9000:9000 -p 127.0.0.1:5052:5052 -v ${HOME}/.lighthouse:/root/.lighthouse sigp/lighthouse lighthouse --network mainnet beacon --http --http-address 0.0.0.0 8 | -------------------------------------------------------------------------------- /packages/web3-eth2-beaconchain/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | [ 4 | '@babel/preset-env', 5 | { 6 | targets: { 7 | node: 'current', 8 | }, 9 | }, 10 | ], 11 | ], 12 | env: { 13 | test: { 14 | plugins: ['@babel/plugin-transform-runtime'] 15 | } 16 | } 17 | }; -------------------------------------------------------------------------------- /packages/web3-eth2-beaconchain/src/index.ts: -------------------------------------------------------------------------------- 1 | import { ETH2Core, BaseAPISchema, ETH2BaseOpts } from 'web3-eth2-core' 2 | import { DefaultSchema } from './schema' 3 | 4 | import { ETH2BeaconChain as IETH2BeaconChain } from '../types' 5 | 6 | // @ts-ignore - ETH2BeaconChain incorrectly implements interface IETH2BeaconChain 7 | // because methods are added during runtime 8 | export class ETH2BeaconChain extends ETH2Core implements IETH2BeaconChain { 9 | constructor( 10 | provider: string, 11 | schema: BaseAPISchema = DefaultSchema, 12 | opts: ETH2BaseOpts = { protectProvider: true }) { 13 | super(provider, schema, opts) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/web3-eth2-beaconchain/test/constructor.test.ts: -------------------------------------------------------------------------------- 1 | import { ETH2BeaconChain } from '../src/index' 2 | 3 | const provider = 'http://127.0.0.1:9596' 4 | const providerSuffix = '/eth/v1/beacon/' 5 | 6 | it('constructs a ETH2BeaconChain instance with expected properties', () => { 7 | const eth2BeaconChain = new ETH2BeaconChain(provider) 8 | expect(eth2BeaconChain.name).toBe('eth2-beaconchain') 9 | expect(eth2BeaconChain.provider).toBe(`${provider}${providerSuffix}`) 10 | expect(eth2BeaconChain.protectProvider) 11 | }) 12 | -------------------------------------------------------------------------------- /packages/web3-eth2-beaconchain/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "unified-signatures": false, 10 | "no-redundant-jsdoc": false, 11 | "interface-name": [true, "always-prefix"] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/web3-eth2-core/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | "@babel/preset-typescript" 5 | ], 6 | "plugins": [ 7 | "@babel/plugin-proposal-class-properties" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-eth2-core/babel.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } -------------------------------------------------------------------------------- /packages/web3-eth2-core/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | roots: ['/test'], 3 | transform: { 4 | '^.+\\.tsx?$': 'ts-jest', 5 | }, 6 | testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$', 7 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], 8 | } -------------------------------------------------------------------------------- /packages/web3-eth2-core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-eth2-core", 3 | "version": "1.0.7", 4 | "description": "Web3 ETH2 core tools for sub-packages. This is an internal package.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth2-core", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types.ts", 11 | "scripts": { 12 | "test": "jest", 13 | "compile": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline", 14 | "type-check": "tsc --noEmit", 15 | "type-check:watch": "npm run type-check -- --watch" 16 | }, 17 | "main": "lib/index.js", 18 | "dependencies": { 19 | "axios": "^0.21.1" 20 | }, 21 | "publishConfig": { 22 | "access": "public" 23 | }, 24 | "devDependencies": { 25 | "@babel/cli": "^7.12.10", 26 | "@babel/core": "^7.12.10", 27 | "@babel/plugin-proposal-class-properties": "^7.12.1", 28 | "@babel/preset-env": "^7.12.11", 29 | "@babel/preset-typescript": "^7.12.7", 30 | "@types/jest": "^26.0.14", 31 | "@types/node": "^14.14.22", 32 | "jest": "^26.5.3", 33 | "ts-jest": "^26.4.4", 34 | "typescript": "^3.9.7" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/web3-eth2-core/test/constructor.test.ts: -------------------------------------------------------------------------------- 1 | import { ETH2Core } from '../src/index' 2 | 3 | const provider = 'http://127.0.0.1:9596' 4 | const testAPISchema = { 5 | packageName: 'testValue', 6 | routePrefix: '/test/route/', 7 | methods: [ 8 | { 9 | name: 'testMethod', 10 | route: 'additional/route', 11 | restMethod: 'get', 12 | inputFormatter: null, 13 | outputFormatter: null, 14 | errors: null, 15 | errorPrefix: 'Test error prefix:' 16 | } 17 | ] 18 | } 19 | 20 | it('constructs a ETH2Core instance with expected properties', () => { 21 | // @ts-ignore using a mock schema for test 22 | const eth2Core = new ETH2Core(provider, testAPISchema, { protectProvider: true }) 23 | 24 | expect(eth2Core.name).toBe(testAPISchema.packageName) 25 | expect(eth2Core.provider).toBe(`${provider}${testAPISchema.routePrefix}`) 26 | expect(eth2Core.protectProvider) 27 | expect(eth2Core.testMethod).toBeDefined() 28 | }) 29 | -------------------------------------------------------------------------------- /packages/web3-eth2-core/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "unified-signatures": false, 10 | "no-redundant-jsdoc": false, 11 | "interface-name": [true, "always-prefix"] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/web3-eth2-core/types.ts: -------------------------------------------------------------------------------- 1 | import { AxiosInstance } from 'axios'; 2 | 3 | export interface ETH2BaseOpts { 4 | protectProvider?: boolean 5 | } 6 | 7 | export type ETH2Function = (...args: any[]) => Promise; 8 | 9 | export interface BaseAPISchemaMethod { 10 | notImplemented?: true, 11 | name: string, 12 | route: string, 13 | restMethod: 'get' | 'post' 14 | inputFormatter: any, 15 | outputFormatter: any, 16 | errors: any 17 | errorPrefix: string 18 | } 19 | 20 | export interface BaseAPISchema { 21 | packageName: string, 22 | routePrefix: string, 23 | methods: BaseAPISchemaMethod[] 24 | } 25 | 26 | export declare class ETH2Core { 27 | private _httpClient; 28 | [key: string]: ETH2Function | any; 29 | name: string; 30 | provider: string | undefined; 31 | protectProvider: boolean; 32 | constructor(provider: string, schema: BaseAPISchema, opts?: ETH2BaseOpts); 33 | static createHttpClient(baseUrl: string): AxiosInstance; 34 | setProvider(provider: string): void; 35 | private routeBuilder; 36 | private buildAPIWrappersFromSchema; 37 | } 38 | -------------------------------------------------------------------------------- /packages/web3-net/README.md: -------------------------------------------------------------------------------- 1 | # web3-net 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is a sub-package of [web3.js][repo]. 6 | 7 | This is the net package used in other [web3.js][repo] packages. 8 | 9 | Please read the [documentation][docs] for more. 10 | 11 | ## Installation 12 | 13 | ### Node.js 14 | 15 | ```bash 16 | npm install web3-net 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | const Web3Net = require('web3-net'); 23 | 24 | const net = new Web3Net('ws://localhost:8546'); 25 | ``` 26 | 27 | ## Types 28 | 29 | All the TypeScript typings are placed in the `types` folder. 30 | 31 | [docs]: http://web3js.readthedocs.io/en/1.0/ 32 | [repo]: https://github.com/ethereum/web3.js 33 | [npm-image]: https://img.shields.io/npm/v/web3-net.svg 34 | [npm-url]: https://npmjs.org/package/web3-net 35 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-net 36 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-net 37 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-net 38 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-net 39 | -------------------------------------------------------------------------------- /packages/web3-net/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-net", 3 | "version": "1.0.8", 4 | "description": "Web3 module to interact with the Ethereum nodes networking properties.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-net", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "@node-real/web3-core-method": "latest", 21 | "web3-core": "1.5.1", 22 | "web3-utils": "1.5.1" 23 | }, 24 | "devDependencies": { 25 | "dtslint": "^3.4.1", 26 | "typescript": "^3.9.5" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/web3-net/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-net/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | web3.js is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | web3.js is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU Lesser General Public License for more details. 11 | You should have received a copy of the GNU Lesser General Public License 12 | along with web3.js. If not, see . 13 | */ 14 | /** 15 | * @file index.d.ts 16 | * @author Josh Stevens 17 | * @date 2018 18 | */ 19 | 20 | import { NetworkBase } from 'web3-core'; 21 | 22 | export class Network extends NetworkBase {} 23 | -------------------------------------------------------------------------------- /packages/web3-net/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-net": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-net/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/web3-providers-http/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-providers-http", 3 | "version": "1.0.8", 4 | "description": "Module to handle web3 RPC connections over HTTP.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-http", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "scripts": { 11 | "compile": "tsc -b tsconfig.json", 12 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 13 | }, 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "types": "types/index.d.ts", 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "web3-core-helpers": "1.5.1", 21 | "xhr2-cookies": "1.1.0" 22 | }, 23 | "devDependencies": { 24 | "dtslint": "^3.4.1", 25 | "typescript": "^3.9.5" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/web3-providers-http/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-providers-http/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-providers": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-providers-http/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/web3-providers-ipc/README.md: -------------------------------------------------------------------------------- 1 | # web3-providers-ipc 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is an IPC provider sub-package for [web3.js][repo]. 6 | 7 | Please read the [documentation][docs] for more. 8 | 9 | ## Installation 10 | 11 | ### Node.js 12 | 13 | ```bash 14 | npm install web3-providers-ipc 15 | ``` 16 | 17 | ## Usage 18 | 19 | ```js 20 | const Web3IpcProvider = require('web3-providers-ipc'); 21 | const net = require(net); 22 | 23 | const ipc = new Web3IpcProvider('/Users/me/Library/Ethereum/geth.ipc', net); 24 | ``` 25 | 26 | ## Types 27 | 28 | All the TypeScript typings are placed in the `types` folder. 29 | 30 | [docs]: http://web3js.readthedocs.io/en/1.0/ 31 | [repo]: https://github.com/ethereum/web3.js 32 | [npm-image]: https://img.shields.io/npm/v/web3-providers-ipc.svg 33 | [npm-url]: https://npmjs.org/package/web3-providers-ipc 34 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-providers-ipc 35 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-providers-ipc 36 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-providers-ipc 37 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-providers-ipc 38 | -------------------------------------------------------------------------------- /packages/web3-providers-ipc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-providers-ipc", 3 | "version": "1.0.7", 4 | "description": "Module to handle web3 RPC connections over IPC sockets.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-ipc", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "scripts": { 11 | "compile": "tsc -b tsconfig.json", 12 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 13 | }, 14 | "types": "types/index.d.ts", 15 | "main": "lib/index.js", 16 | "dependencies": { 17 | "oboe": "2.1.5", 18 | "web3-core-helpers": "1.5.1" 19 | }, 20 | "publishConfig": { 21 | "access": "public" 22 | }, 23 | "devDependencies": { 24 | "@types/node": "^12.12.6", 25 | "dtslint": "^3.4.1", 26 | "typescript": "^3.9.5" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/web3-providers-ipc/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-providers-ipc/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file index.d.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import { IpcProviderBase } from 'web3-core-helpers'; 24 | 25 | export class IpcProvider extends IpcProviderBase { } 26 | -------------------------------------------------------------------------------- /packages/web3-providers-ipc/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-providers": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-providers-ipc/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/web3-providers-ws/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-providers-ws", 3 | "version": "1.0.7", 4 | "description": "Module to handle web3 RPC connections over WebSockets.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-ws", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "scripts": { 11 | "compile": "tsc -b tsconfig.json", 12 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 13 | }, 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "types": "types/index.d.ts", 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "eventemitter3": "4.0.4", 21 | "web3-core-helpers": "1.5.1", 22 | "websocket": "^1.0.32" 23 | }, 24 | "devDependencies": { 25 | "dtslint": "^3.4.1", 26 | "typescript": "^3.9.5" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/web3-providers-ws/src/helpers.js: -------------------------------------------------------------------------------- 1 | var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]'; 2 | var isRN = typeof navigator !== 'undefined' && navigator.product === 'ReactNative'; 3 | 4 | var _btoa = null; 5 | var helpers = null; 6 | if (isNode || isRN) { 7 | _btoa = function(str) { 8 | return Buffer.from(str).toString('base64'); 9 | }; 10 | var url = require('url'); 11 | if (url.URL) { 12 | // Use the new Node 6+ API for parsing URLs that supports username/password 13 | var newURL = url.URL; 14 | helpers = function(url) { 15 | return new newURL(url); 16 | }; 17 | } else { 18 | // Web3 supports Node.js 5, so fall back to the legacy URL API if necessary 19 | helpers = require('url').parse; 20 | } 21 | } else { 22 | _btoa = btoa.bind(window); 23 | helpers = function(url) { 24 | return new URL(url); 25 | }; 26 | } 27 | 28 | module.exports = { 29 | parseURL: helpers, 30 | btoa: _btoa 31 | }; 32 | -------------------------------------------------------------------------------- /packages/web3-providers-ws/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-providers-ws/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file index.d.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import { WebsocketProviderBase } from 'web3-core-helpers'; 24 | 25 | export class WebsocketProvider extends WebsocketProviderBase { } 26 | -------------------------------------------------------------------------------- /packages/web3-providers-ws/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-providers": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-providers-ws/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/web3-shh/README.md: -------------------------------------------------------------------------------- 1 | # web3-shh 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is a sub-package of [web3.js][repo] 6 | 7 | This is the whisper v5 package. 8 | 9 | Please read the [documentation][docs] for more. 10 | 11 | ## Installation 12 | 13 | ### Node.js 14 | 15 | ```bash 16 | npm install web3-shh 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | const Web3Personal = require('web3-shh'); 23 | 24 | const shh = new Web3Personal('ws://localhost:8546'); 25 | ``` 26 | 27 | ## Types 28 | 29 | All the TypeScript typings are placed in the `types` folder. 30 | 31 | [docs]: http://web3js.readthedocs.io/en/1.0/ 32 | [repo]: https://github.com/ethereum/web3.js 33 | [npm-image]: https://img.shields.io/npm/v/web3-shh.svg 34 | [npm-url]: https://npmjs.org/package/web3-shh 35 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-shh 36 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-shh 37 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-shh 38 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-shh 39 | -------------------------------------------------------------------------------- /packages/web3-shh/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-shh", 3 | "version": "1.0.8", 4 | "description": "Web3 module to interact with the Whisper messaging protocol.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-shh", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types", 14 | "postinstall": "echo \"WARNING: the web3-shh api will be deprecated in the next version\"" 15 | }, 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "main": "lib/index.js", 20 | "dependencies": { 21 | "@node-real/web3-core-method": "latest", 22 | "web3-core": "1.5.1", 23 | "web3-core-subscriptions": "1.5.1", 24 | "web3-net": "1.5.1" 25 | }, 26 | "devDependencies": { 27 | "@types/node": "^12.12.6", 28 | "dtslint": "^3.4.1", 29 | "typescript": "^3.9.5" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/web3-shh/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-shh/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-shh": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-shh/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "unified-signatures": false 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/web3-utils/README.md: -------------------------------------------------------------------------------- 1 | # web3-utils 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is a sub-package of [web3.js][repo]. 6 | 7 | This contains useful utility functions for Dapp developers. 8 | 9 | Please read the [documentation][docs] for more. 10 | 11 | ## Installation 12 | 13 | ### Node.js 14 | 15 | ```bash 16 | npm install web3-utils 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | const Web3Utils = require('web3-utils'); 23 | console.log(Web3Utils); 24 | { 25 | sha3: function(){}, 26 | soliditySha3: function(){}, 27 | isAddress: function(){}, 28 | ... 29 | } 30 | ``` 31 | 32 | ## Types 33 | 34 | All the TypeScript typings are placed in the `types` folder. 35 | 36 | [docs]: http://web3js.readthedocs.io/en/1.0/ 37 | [repo]: https://github.com/ethereum/web3.js 38 | [npm-image]: https://img.shields.io/npm/v/web3-utils.svg 39 | [npm-url]: https://npmjs.org/package/web3-utils 40 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3-utils 41 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3-utils 42 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3-utils 43 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3-utils 44 | -------------------------------------------------------------------------------- /packages/web3-utils/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@node-real/web3-utils", 3 | "version": "1.0.7", 4 | "description": "Collection of utility functions used in web3.js.", 5 | "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-utils", 6 | "license": "LGPL-3.0", 7 | "engines": { 8 | "node": ">=8.0.0" 9 | }, 10 | "types": "types/index.d.ts", 11 | "scripts": { 12 | "compile": "tsc -b tsconfig.json", 13 | "dtslint": "dtslint --localTs ../../node_modules/typescript/lib types" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "main": "lib/index.js", 19 | "dependencies": { 20 | "bn.js": "^4.11.9", 21 | "eth-lib": "0.2.8", 22 | "ethereum-bloom-filters": "^1.0.6", 23 | "ethjs-unit": "0.1.6", 24 | "number-to-bn": "1.7.0", 25 | "randombytes": "^2.1.0", 26 | "utf8": "3.0.0" 27 | }, 28 | "devDependencies": { 29 | "dtslint": "^3.4.1", 30 | "typescript": "^3.9.5" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/web3-utils/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/bytes-to-hex-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file bytes-to-hex-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {bytesToHex} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | bytesToHex([72]); 28 | 29 | // $ExpectError 30 | bytesToHex(['string']); 31 | // $ExpectError 32 | bytesToHex(345); 33 | // $ExpectError 34 | bytesToHex(new BN(3)); 35 | // $ExpectError 36 | bytesToHex({}); 37 | // $ExpectError 38 | bytesToHex(true); 39 | // $ExpectError 40 | bytesToHex(['string']); 41 | // $ExpectError 42 | bytesToHex(null); 43 | // $ExpectError 44 | bytesToHex(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/from-ascii-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file from-ascii-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {fromAscii} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | fromAscii('I have 100!'); 28 | 29 | // $ExpectError 30 | fromAscii(345); 31 | // $ExpectError 32 | fromAscii(new BN(3)); 33 | // $ExpectError 34 | fromAscii({}); 35 | // $ExpectError 36 | fromAscii(true); 37 | // $ExpectError 38 | fromAscii(['string']); 39 | // $ExpectError 40 | fromAscii([4]); 41 | // $ExpectError 42 | fromAscii(null); 43 | // $ExpectError 44 | fromAscii(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/from-decimal-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file from-decimal-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {fromDecimal} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | fromDecimal('232'); 28 | // $ExpectType string 29 | fromDecimal(232); 30 | 31 | // $ExpectError 32 | fromDecimal(new BN(3)); 33 | // $ExpectError 34 | fromDecimal(['string']); 35 | // $ExpectError 36 | fromDecimal([4]); 37 | // $ExpectError 38 | fromDecimal({}); 39 | // $ExpectError 40 | fromDecimal(true); 41 | // $ExpectError 42 | fromDecimal(null); 43 | // $ExpectError 44 | fromDecimal(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/from-utf8-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file from-utf8-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {fromUtf8} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | fromUtf8('I have 100£'); 28 | 29 | // $ExpectError 30 | fromUtf8(232); 31 | // $ExpectError 32 | fromUtf8(new BN(3)); 33 | // $ExpectError 34 | fromUtf8(['string']); 35 | // $ExpectError 36 | fromUtf8([4]); 37 | // $ExpectError 38 | fromUtf8({}); 39 | // $ExpectError 40 | fromUtf8(true); 41 | // $ExpectError 42 | fromUtf8(null); 43 | // $ExpectError 44 | fromUtf8(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/hex-to-ascii-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file hex-to-ascii-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {hexToAscii} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | hexToAscii('0x4920686176652031303021'); 28 | 29 | // $ExpectError 30 | hexToAscii(345); 31 | // $ExpectError 32 | hexToAscii(new BN(3)); 33 | // $ExpectError 34 | hexToAscii({}); 35 | // $ExpectError 36 | hexToAscii(true); 37 | // $ExpectError 38 | hexToAscii(['string']); 39 | // $ExpectError 40 | hexToAscii([4]); 41 | // $ExpectError 42 | hexToAscii(null); 43 | // $ExpectError 44 | hexToAscii(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/hex-to-bytes-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file hex-to-bytes-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {hexToBytes} from 'web3-utils'; 25 | 26 | // $ExpectType number[] 27 | hexToBytes('0x000000ea'); 28 | // $ExpectType number[] 29 | hexToBytes(0x000000ea); 30 | 31 | // $ExpectError 32 | hexToBytes([4]); 33 | // $ExpectError 34 | hexToBytes(['string']); 35 | // $ExpectError 36 | hexToBytes(new BN(3)); 37 | // $ExpectError 38 | hexToBytes({}); 39 | // $ExpectError 40 | hexToBytes(true); 41 | // $ExpectError 42 | hexToBytes(null); 43 | // $ExpectError 44 | hexToBytes(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/hex-to-number-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file hex-to-number-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {hexToNumber} from 'web3-utils'; 25 | 26 | // $ExpectType number 27 | hexToNumber('232'); 28 | // $ExpectType number 29 | hexToNumber(232); 30 | 31 | // $ExpectError 32 | hexToNumber(new BN(3)); 33 | // $ExpectError 34 | hexToNumber(['string']); 35 | // $ExpectError 36 | hexToNumber([4]); 37 | // $ExpectError 38 | hexToNumber({}); 39 | // $ExpectError 40 | hexToNumber(true); 41 | // $ExpectError 42 | hexToNumber(null); 43 | // $ExpectError 44 | hexToNumber(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/hex-to-utf8-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file hex-to-utf8-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {hexToUtf8} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | hexToUtf8('0x49206861766520313030e282ac'); 28 | 29 | // $ExpectError 30 | hexToUtf8(656); 31 | // $ExpectError 32 | hexToUtf8(new BN(3)); 33 | // $ExpectError 34 | hexToUtf8(['string']); 35 | // $ExpectError 36 | hexToUtf8([4]); 37 | // $ExpectError 38 | hexToUtf8({}); 39 | // $ExpectError 40 | hexToUtf8(true); 41 | // $ExpectError 42 | hexToUtf8(null); 43 | // $ExpectError 44 | hexToUtf8(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/is-big-number-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file is-big-number-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {isBigNumber} from 'web3-utils'; 25 | 26 | // $ExpectType boolean 27 | isBigNumber(new BN(3)); 28 | 29 | // $ExpectError 30 | isBigNumber(7); 31 | // $ExpectError 32 | isBigNumber('4325'); 33 | // $ExpectError 34 | isBigNumber({}); 35 | // $ExpectError 36 | isBigNumber(true); 37 | // $ExpectError 38 | isBigNumber(['string']); 39 | // $ExpectError 40 | isBigNumber([4]); 41 | // $ExpectError 42 | isBigNumber(null); 43 | // $ExpectError 44 | isBigNumber(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/is-bloom-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file is-bloom-tests.ts 19 | * @author Josh Stevens 20 | * @date 2019 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import { isBloom } from 'web3-utils'; 25 | 26 | // $ExpectType boolean 27 | isBloom('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'); 28 | 29 | // $ExpectError 30 | isBloom(656); 31 | // $ExpectError 32 | isBloom(new BN(3)); 33 | // $ExpectError 34 | isBloom(['string']); 35 | // $ExpectError 36 | isBloom([4]); 37 | // $ExpectError 38 | isBloom({}); 39 | // $ExpectError 40 | isBloom(true); 41 | // $ExpectError 42 | isBloom(null); 43 | // $ExpectError 44 | isBloom(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/is-bn-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file is-bn-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {isBN} from 'web3-utils'; 25 | 26 | // $ExpectType boolean 27 | isBN(7); 28 | // $ExpectType boolean 29 | isBN('4325'); 30 | 31 | // $ExpectError 32 | isBN({}); 33 | // $ExpectError 34 | isBN(true); 35 | // $ExpectError 36 | isBN(new BN(3)); 37 | // $ExpectError 38 | isBN(['string']); 39 | // $ExpectError 40 | isBN([4]); 41 | // $ExpectError 42 | isBN(null); 43 | // $ExpectError 44 | isBN(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/is-hex-strict-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file is-hex-strict-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {isHexStrict} from 'web3-utils'; 25 | 26 | // $ExpectType boolean 27 | isHexStrict('0xc1912'); 28 | // $ExpectType boolean 29 | isHexStrict(345); 30 | 31 | // $ExpectError 32 | isHexStrict(new BN(3)); 33 | // $ExpectError 34 | isHexStrict({}); 35 | // $ExpectError 36 | isHexStrict(true); 37 | // $ExpectError 38 | isHexStrict(['string']); 39 | // $ExpectError 40 | isHexStrict([4]); 41 | // $ExpectError 42 | isHexStrict(null); 43 | // $ExpectError 44 | isHexStrict(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/is-hex-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file is-hex-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {isHex} from 'web3-utils'; 25 | 26 | // $ExpectType boolean 27 | isHex('0xc1912'); 28 | // $ExpectType boolean 29 | isHex(345); 30 | 31 | // $ExpectError 32 | isHex(new BN(3)); 33 | // $ExpectError 34 | isHex({}); 35 | // $ExpectError 36 | isHex(true); 37 | // $ExpectError 38 | isHex(['string']); 39 | // $ExpectError 40 | isHex([4]); 41 | // $ExpectError 42 | isHex(null); 43 | // $ExpectError 44 | isHex(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/is-topic-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file is-topic-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {isTopic} from 'web3-utils'; 25 | 26 | // $ExpectType boolean 27 | isTopic('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'); 28 | 29 | // $ExpectError 30 | isTopic(656); 31 | // $ExpectError 32 | isTopic(new BN(3)); 33 | // $ExpectError 34 | isTopic(['string']); 35 | // $ExpectError 36 | isTopic([4]); 37 | // $ExpectError 38 | isTopic({}); 39 | // $ExpectError 40 | isTopic(true); 41 | // $ExpectError 42 | isTopic(null); 43 | // $ExpectError 44 | isTopic(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/is-topic.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file is-user-ethereum-address-in-bloom.ts 19 | * @author Josh Stevens 20 | * @date 2019 21 | */ 22 | 23 | import { isTopic } from 'web3-utils'; 24 | 25 | // $ExpectType boolean 26 | isTopic('0x000000000000000000000000b3bb037d2f2341a1c2775d51909a3d944597987d'); 27 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/keccak256-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file keccak256-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {keccak256} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | keccak256('234'); 28 | // $ExpectType string 29 | keccak256(new BN(3)); 30 | 31 | // $ExpectError 32 | keccak256(['string']); 33 | // $ExpectError 34 | keccak256(234); 35 | // $ExpectError 36 | keccak256([4]); 37 | // $ExpectError 38 | keccak256({}); 39 | // $ExpectError 40 | keccak256(true); 41 | // $ExpectError 42 | keccak256(null); 43 | // $ExpectError 44 | keccak256(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/random-hex-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file random-hex-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {randomHex} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | randomHex(32); 28 | 29 | // $ExpectError 30 | randomHex('234'); 31 | // $ExpectError 32 | randomHex(new BN(3)); 33 | // $ExpectError 34 | randomHex(['string']); 35 | // $ExpectError 36 | randomHex([4]); 37 | // $ExpectError 38 | randomHex({}); 39 | // $ExpectError 40 | randomHex(true); 41 | // $ExpectError 42 | randomHex(null); 43 | // $ExpectError 44 | randomHex(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/sha3-raw-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file sha3Raw-tests.ts 19 | * @author Samuel Furter 20 | * @date 2019 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {sha3Raw} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | sha3Raw('234'); 28 | // $ExpectType string 29 | sha3Raw(new BN(3)); 30 | 31 | // $ExpectError 32 | sha3Raw(['string']); 33 | // $ExpectError 34 | sha3Raw(234); 35 | // $ExpectError 36 | sha3Raw([4]); 37 | // $ExpectError 38 | sha3Raw({}); 39 | // $ExpectError 40 | sha3Raw(true); 41 | // $ExpectError 42 | sha3Raw(null); 43 | // $ExpectError 44 | sha3Raw(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/sha3-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file sha3-tests.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {sha3} from 'web3-utils'; 25 | 26 | // $ExpectType string | null 27 | sha3('234'); 28 | // $ExpectType string | null 29 | sha3(new BN(3)); 30 | 31 | // $ExpectError 32 | sha3(['string']); 33 | // $ExpectError 34 | sha3(234); 35 | // $ExpectError 36 | sha3([4]); 37 | // $ExpectError 38 | sha3({}); 39 | // $ExpectError 40 | sha3(true); 41 | // $ExpectError 42 | sha3(null); 43 | // $ExpectError 44 | sha3(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/string-to-hex-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file string-to-hex-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {stringToHex} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | stringToHex('I have 100£'); 28 | 29 | // $ExpectError 30 | stringToHex(232); 31 | // $ExpectError 32 | stringToHex(new BN(3)); 33 | // $ExpectError 34 | stringToHex(['string']); 35 | // $ExpectError 36 | stringToHex([4]); 37 | // $ExpectError 38 | stringToHex({}); 39 | // $ExpectError 40 | stringToHex(true); 41 | // $ExpectError 42 | stringToHex(null); 43 | // $ExpectError 44 | stringToHex(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/to-ascii-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file to-ascii-tests.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {toAscii} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | toAscii('0x4920686176652031303021'); 28 | 29 | // $ExpectError 30 | toAscii(345); 31 | // $ExpectError 32 | toAscii(new BN(3)); 33 | // $ExpectError 34 | toAscii({}); 35 | // $ExpectError 36 | toAscii(true); 37 | // $ExpectError 38 | toAscii(['string']); 39 | // $ExpectError 40 | toAscii([4]); 41 | // $ExpectError 42 | toAscii(null); 43 | // $ExpectError 44 | toAscii(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/to-bn-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file to-bn-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import {toBN} from 'web3-utils'; 24 | 25 | // $ExpectType BN 26 | toBN(4); 27 | // $ExpectType BN 28 | toBN('443'); 29 | 30 | // $ExpectError 31 | toBN({}); 32 | // $ExpectError 33 | toBN(true); 34 | // $ExpectError 35 | toBN(['string']); 36 | // $ExpectError 37 | toBN([4]); 38 | // $ExpectError 39 | toBN(null); 40 | // $ExpectError 41 | toBN(undefined); 42 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/to-decimal-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file to-decimal-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {toDecimal} from 'web3-utils'; 25 | 26 | // $ExpectType number 27 | toDecimal('232'); 28 | // $ExpectType number 29 | toDecimal(232); 30 | 31 | // $ExpectError 32 | toDecimal(new BN(3)); 33 | // $ExpectError 34 | toDecimal(['string']); 35 | // $ExpectError 36 | toDecimal([4]); 37 | // $ExpectError 38 | toDecimal({}); 39 | // $ExpectError 40 | toDecimal(true); 41 | // $ExpectError 42 | toDecimal(null); 43 | // $ExpectError 44 | toDecimal(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/to-hex-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file to-hex-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {toHex} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | toHex('234'); 28 | // $ExpectType string 29 | toHex(234); 30 | // $ExpectType string 31 | toHex(new BN(3)); 32 | 33 | // $ExpectError 34 | toHex(['string']); 35 | // $ExpectError 36 | toHex(true); 37 | // $ExpectError 38 | toHex([4]); 39 | // $ExpectError 40 | toHex({}); 41 | // $ExpectError 42 | toHex(null); 43 | // $ExpectError 44 | toHex(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/to-number-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file to-number-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {toNumber} from 'web3-utils'; 25 | 26 | // $ExpectType number 27 | toNumber('234'); 28 | // $ExpectType number 29 | toNumber(234); 30 | // $ExpectType number 31 | toNumber(new BN(3)); 32 | 33 | // $ExpectError 34 | toNumber(['string']); 35 | // $ExpectError 36 | toNumber(true); 37 | // $ExpectError 38 | toNumber([4]); 39 | // $ExpectError 40 | toNumber({}); 41 | // $ExpectError 42 | toNumber(null); 43 | // $ExpectError 44 | toNumber(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/to-utf8-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file to-utf8-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {toUtf8} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | toUtf8('0x49206861766520313030e282ac'); 28 | 29 | // $ExpectError 30 | toUtf8(656); 31 | // $ExpectError 32 | toUtf8(new BN(3)); 33 | // $ExpectError 34 | toUtf8(['string']); 35 | // $ExpectError 36 | toUtf8([4]); 37 | // $ExpectError 38 | toUtf8({}); 39 | // $ExpectError 40 | toUtf8(true); 41 | // $ExpectError 42 | toUtf8(null); 43 | // $ExpectError 44 | toUtf8(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/unit-map-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file unit-map-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import {unitMap} from 'web3-utils'; 24 | 25 | // $ExpectType Units 26 | unitMap(); 27 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tests/utf8-to-hex-test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file utf8-to-hex-test.ts 19 | * @author Josh Stevens 20 | * @date 2018 21 | */ 22 | 23 | import BN = require('bn.js'); 24 | import {utf8ToHex} from 'web3-utils'; 25 | 26 | // $ExpectType string 27 | utf8ToHex('I have 100£'); 28 | 29 | // $ExpectError 30 | utf8ToHex(232); 31 | // $ExpectError 32 | utf8ToHex(new BN(3)); 33 | // $ExpectError 34 | utf8ToHex(['string']); 35 | // $ExpectError 36 | utf8ToHex([4]); 37 | // $ExpectError 38 | utf8ToHex({}); 39 | // $ExpectError 40 | utf8ToHex(true); 41 | // $ExpectError 42 | utf8ToHex(null); 43 | // $ExpectError 44 | utf8ToHex(undefined); 45 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3-utils": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3-utils/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-redundant-jsdoc": false, 9 | "max-line-length": false 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/web3/README.md: -------------------------------------------------------------------------------- 1 | # web3 2 | 3 | [![NPM Package][npm-image]][npm-url] [![Dependency Status][deps-image]][deps-url] [![Dev Dependency Status][deps-dev-image]][deps-dev-url] 4 | 5 | This is the main package of [web3.js][repo]. 6 | 7 | Please read the main [README][repo-readme] and [documentation][docs] for more. 8 | 9 | ## Installation 10 | 11 | ### Node.js 12 | 13 | ```bash 14 | npm install web3 15 | ``` 16 | 17 | ## Types 18 | 19 | All the TypeScript typings are placed in the `types` folder. 20 | 21 | [docs]: http://web3js.readthedocs.io/en/1.0/ 22 | [repo]: https://github.com/ethereum/web3.js 23 | [repo-readme]: https://github.com/ethereum/web3.js/blob/1.x/README.md 24 | [npm-image]: https://img.shields.io/npm/v/web3.svg 25 | [npm-url]: https://npmjs.org/package/web3 26 | [deps-image]: https://david-dm.org/ethereum/web3.js/1.x/status.svg?path=packages/web3 27 | [deps-url]: https://david-dm.org/ethereum/web3.js/1.x?path=packages/web3 28 | [deps-dev-image]: https://david-dm.org/ethereum/web3.js/1.x/dev-status.svg?path=packages/web3 29 | [deps-dev-url]: https://david-dm.org/ethereum/web3.js/1.x?type=dev&path=packages/web3 -------------------------------------------------------------------------------- /packages/web3/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib" 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/web3/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "noImplicitThis": true, 8 | "strictNullChecks": true, 9 | "strictFunctionTypes": true, 10 | "noEmit": true, 11 | "allowSyntheticDefaultImports": false, 12 | "baseUrl": ".", 13 | "paths": { 14 | "web3": ["."] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/web3/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "semicolon": false, 5 | "no-import-default-of-export-equals": false, 6 | "file-name-casing": [true, "kebab-case"], 7 | "whitespace": false, 8 | "no-unnecessary-class": false, 9 | "unified-signatures": false 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /scripts/e2e.cdn.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------- 4 | # Prepares a small test site that uses the packages/web3/dist/min 5 | # -------------------------------------------------------------------- 6 | 7 | if [ -z "$CI" ]; then 8 | 9 | echo "======================================================================" 10 | echo "This script prepares a test site for Netlify. Only run in CI. " 11 | echo "======================================================================" 12 | 13 | exit 1 14 | 15 | fi 16 | 17 | echo "======================================================================" 18 | echo "Preparing test site for web3-staging.netlify.app " 19 | echo "======================================================================" 20 | 21 | cp packages/web3/dist/web3.min.js scripts/html 22 | 23 | cd scripts/html 24 | 25 | BUNDLE_SIZE=$(wc -c web3.min.js | awk '{print $1}') 26 | 27 | # Mark file with current commit, branch, and bundle size. 28 | sed -i "s|__COMMIT_HASH__|$COMMIT_REF|g" index.html 29 | sed -i "s|__BRANCH__|$BRANCH|g" index.html 30 | sed -i "s|__BUNDLE_SIZE__|$BUNDLE_SIZE|g" index.html 31 | 32 | -------------------------------------------------------------------------------- /scripts/e2e.chrome.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # ------------------------------------------------------------------------------------- 4 | # Runs mocha tests tagged 'e2e' vs chrome headless + insta-mining ganache client 5 | # ------------------------------------------------------------------------------------- 6 | 7 | # Exit immediately on error 8 | set -o errexit 9 | 10 | # Run cleanup on exit 11 | trap cleanup EXIT 12 | 13 | cleanup() { 14 | if [ -n "$client" ]; then 15 | kill -9 $client 16 | fi 17 | } 18 | 19 | echo " " 20 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 21 | echo "E2E: chrome headless browser " 22 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 23 | echo " " 24 | 25 | # Launch ganache, track its PID and wait until port is open 26 | npx ganache-cli --noVMErrorsOnRPCResponse > /dev/null & 27 | client=$! 28 | npx wait-port 8545 29 | 30 | # Test 31 | karma start \ 32 | --single-run \ 33 | --browsers ChromeHeadless 34 | -------------------------------------------------------------------------------- /scripts/e2e.firefox.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # ------------------------------------------------------------------------------------- 4 | # Runs mocha tests tagged 'e2e' vs firefox headless + insta-mining ganache client 5 | # ------------------------------------------------------------------------------------- 6 | 7 | # Exit immediately on error 8 | set -o errexit 9 | 10 | # Run cleanup on exit 11 | trap cleanup EXIT 12 | 13 | cleanup() { 14 | if [ -n "$client" ]; then 15 | kill -9 $client 16 | fi 17 | } 18 | 19 | echo " " 20 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 21 | echo "E2E: firefox headless browser " 22 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 23 | echo " " 24 | 25 | # Launch ganache, track its PID and wait until port is open 26 | npx ganache-cli --noVMErrorsOnRPCResponse > /dev/null & 27 | client=$! 28 | npx wait-port 8545 29 | 30 | # Test 31 | karma start \ 32 | --single-run \ 33 | --browsers FirefoxHeadless 34 | -------------------------------------------------------------------------------- /scripts/e2e.ganache.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------- 4 | # Runs mocha tests tagged 'e2e' using an insta-mining ganache client 5 | # -------------------------------------------------------------------- 6 | 7 | # Exit immediately on error 8 | set -o errexit 9 | 10 | # Run cleanup on exit 11 | trap cleanup EXIT 12 | 13 | cleanup() { 14 | if [ -n "$client" ]; then 15 | kill -9 $client 16 | fi 17 | } 18 | 19 | echo " " 20 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 21 | echo "E2E: ganache insta-mining " 22 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 23 | echo " " 24 | 25 | # Launch ganache, track its PID and wait until port is open 26 | npx ganache-cli --noVMErrorsOnRPCResponse > /dev/null & 27 | client=$! 28 | npx wait-port 8545 29 | 30 | # Test 31 | GANACHE=true nyc --no-clean --silent _mocha -- \ 32 | --reporter spec \ 33 | --require ts-node/register \ 34 | --grep 'E2E' \ 35 | --timeout 5000 \ 36 | --exit 37 | -------------------------------------------------------------------------------- /scripts/e2e.geth.automine.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------- 4 | # Runs mocha tests tagged 'e2e' using an auto-mining geth dev client 5 | # -------------------------------------------------------------------- 6 | 7 | 8 | # Exit immediately on error 9 | set -o errexit 10 | 11 | # Run cleanup on exit 12 | trap cleanup EXIT 13 | 14 | cleanup(){ 15 | docker stop geth-client 16 | } 17 | 18 | echo " " 19 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 20 | echo "E2E: geth auto-mining 2s (requires docker) " 21 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 22 | echo " " 23 | 24 | # Launch client w/ two unlocked accounts. 25 | # + accounts[0] default geth unlocked bal = ~infinity 26 | # + accounts[1] unlocked, signing password = 'left-hand-of-darkness' 27 | geth-dev-assistant --period 2 --accounts 1 --tag 'stable' 28 | 29 | # Test 30 | GETH_AUTOMINE=true nyc --no-clean --silent _mocha -- \ 31 | --reporter spec \ 32 | --grep 'E2E' \ 33 | --timeout 15000 \ 34 | --exit 35 | -------------------------------------------------------------------------------- /scripts/e2e.geth.instamine.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------- 4 | # Runs mocha tests tagged 'e2e' using an insta-mining geth dev client 5 | # -------------------------------------------------------------------- 6 | 7 | 8 | # Exit immediately on error 9 | set -o errexit 10 | 11 | # Run cleanup on exit 12 | trap cleanup EXIT 13 | 14 | cleanup(){ 15 | docker stop geth-client 16 | } 17 | 18 | echo " " 19 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 20 | echo "E2E: geth insta-mining (requires docker) " 21 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 22 | echo " " 23 | 24 | # Launch client w/ two unlocked accounts. 25 | # + accounts[0] default geth unlocked bal = ~infinity 26 | # + accounts[1] unlocked, bal=50 eth, signing password = 'left-hand-of-darkness' 27 | geth-dev-assistant --accounts 1 --tag 'stable' 28 | 29 | # Test 30 | GETH_INSTAMINE=true nyc --no-clean --silent _mocha -- \ 31 | --reporter spec \ 32 | --grep 'E2E' \ 33 | --timeout 15000 \ 34 | --exit 35 | -------------------------------------------------------------------------------- /scripts/e2e.min.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # ------------------------------------------------------------------------------------- 4 | # Runs basic min bundle loading check on chrome headless 5 | # ------------------------------------------------------------------------------------- 6 | 7 | # Exit immediately on error 8 | set -o errexit 9 | 10 | echo " " 11 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 12 | echo "E2E: web3/dist/web3.min.js (Chrome). " 13 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 14 | echo " " 15 | 16 | BROWSER_BUNDLE_TEST="publishedDist" karma start \ 17 | --single-run \ 18 | --browsers ChromeHeadless 19 | 20 | echo " " 21 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 22 | echo "E2E: web3/dist/web3.min.js (Chrome). " 23 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 24 | echo " " 25 | 26 | BROWSER_BUNDLE_TEST="gitRepoDist" karma start \ 27 | --single-run \ 28 | --browsers ChromeHeadless 29 | -------------------------------------------------------------------------------- /scripts/e2e.windows.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This script installs Web3 from virtual registry in a 4 | # Windows env and runs some simple Web3 calls. 5 | 6 | # Exit immediately on error 7 | set -o errexit 8 | 9 | # Setup mock project to install web3 from virtual registry 10 | mkdir windows_test 11 | cp scripts/js/basic_usage.js windows_test/basic_usage.js 12 | cd windows_test 13 | 14 | # Install web3 as dep 15 | npm init --yes 16 | npm install web3@e2e --save --registry http://localhost:4873 17 | ./basic_usage.js 18 | 19 | # Shutdown verdaccio server 20 | cd .. 21 | source verdaccio_pid 22 | kill -9 $VERDACCIO_PID 23 | 24 | # Terminate stray node process 25 | if [ ! -z "$CI" ]; then 26 | kill -9 $(grep node <(ps -ef) | sed 's/.*\travis *\([0-9]*\).*/\1/') 27 | fi 28 | -------------------------------------------------------------------------------- /scripts/eth2.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------- 4 | # 5 | # -------------------------------------------------------------------- 6 | 7 | 8 | # Exit immediately on error 9 | set -o errexit 10 | 11 | # Run cleanup on exit 12 | trap cleanup EXIT 13 | 14 | cleanup(){ 15 | docker stop $(docker ps -a -q) 16 | } 17 | 18 | echo " " 19 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 20 | echo "ETH2: Lighthouse Node (requires docker) " 21 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 22 | echo " " 23 | 24 | nohup docker run -p 9000:9000 -p 127.0.0.1:5052:5052 -v ${HOME}/.lighthouse:/root/.lighthouse sigp/lighthouse lighthouse --network mainnet beacon --http --http-address 0.0.0.0 > /dev/null 2>&1 & 25 | 26 | npm run build 27 | 28 | # Test 29 | npm --prefix ./packages/web3-eth2-core run test 30 | npm --prefix ./packages/web3-eth2-beaconchain run test 31 | -------------------------------------------------------------------------------- /scripts/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Web3.js!

8 |

9 |

Latest Block

10 | 11 |

12 |

13 |

14 |

15 |

16 |

17 | 18 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /test/2_givenProvider-currentProvider.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var decache = require('decache'); 4 | 5 | describe('Web3.providers.currentProvider', function () { 6 | 7 | // Setting of 'global.' requires a deep reset 8 | beforeEach(function(){ 9 | decache('../packages/web3'); 10 | decache('../packages/web3-eth'); 11 | decache('../packages/web3-bzz'); 12 | }); 13 | 14 | describe('should be set if web3.currentProvider is available', function () { 15 | beforeEach(function(){ 16 | global.web3 = {currentProvider: {bzz: 'http://givenProvider:8501'}}; 17 | }); 18 | 19 | it('when instantiating Web3', function () { 20 | var Web3 = require('../packages/web3'); 21 | assert.deepEqual(Web3.givenProvider, global.web3.currentProvider); 22 | }); 23 | 24 | it('when instantiating Eth', function () { 25 | var Eth = require('../packages/web3-eth'); 26 | assert.deepEqual(Eth.givenProvider, global.web3.currentProvider); 27 | }); 28 | }); 29 | }); 30 | 31 | -------------------------------------------------------------------------------- /test/config/ensAddresses.json: -------------------------------------------------------------------------------- 1 | {"registry":"0xDC9fdC7554013F17eBDEAFD00F5027373a42D006","resolver":"0xCBbB6622a8A1c97fdA8e314b3812E53b33443799","fifsRegistrar":"0x78331aC1b53ea39A5b442A5c8656b556abCA7FeB","reverseRegistrar":"0x003A653191147bF09880aA162b30956AF3714AC1"} -------------------------------------------------------------------------------- /test/e2e.minified.js: -------------------------------------------------------------------------------- 1 | // Simple check to make sure window.web3 is defined for the karma min loading tests 2 | describe('window.Web3 is defined', function () { 3 | 4 | // Referencing `process` throws w/out browserify. 5 | // We want to be skipped during the browserified units tests here. 6 | it("loads", function(){ 7 | try { if (process) return } catch (e) {} 8 | 9 | if (!window.Web3) throw new Error('"window.Web3" was not defined'); 10 | }); 11 | }) 12 | -------------------------------------------------------------------------------- /test/errors.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | 4 | var errors = require('../packages/web3-core-helpers/src/errors.js'); 5 | 6 | describe('lib/web3/method', function () { 7 | describe('getCall', function () { 8 | 9 | for(var key in errors) { 10 | it('should return and error', function () { 11 | 12 | assert.instanceOf(errors[key](), Error); 13 | }); 14 | } 15 | 16 | }); 17 | }); 18 | 19 | -------------------------------------------------------------------------------- /test/eth.abi.decodeParameter.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Abi = require('../packages/web3-eth-abi'); 4 | 5 | var tests = [{ 6 | params: ['uint256', '0x0000000000000000000000000000000000000000000000000000000000000010'], 7 | result: "16" 8 | },{ 9 | params: ['string', '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000'], 10 | result: "Hello!%!" 11 | }]; 12 | 13 | describe('decodeParameter', function () { 14 | tests.forEach(function (test) { 15 | it('should convert correctly', function () { 16 | assert.equal(Abi.decodeParameter.apply(Abi, test.params), test.result); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /test/eth.abi.encodeEventSignature.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Abi = require('../packages/web3-eth-abi'); 4 | 5 | var tests = [{ 6 | params: [{ 7 | name: 'myEvent', 8 | type: 'event', 9 | inputs: [{ 10 | type: 'uint256', 11 | name: 'myNumber' 12 | },{ 13 | type: 'bytes32', 14 | name: 'myBytes' 15 | }] 16 | }], 17 | result: '0xf2eeb729e636a8cb783be044acf6b7b1e2c5863735b60d6daae84c366ee87d97' 18 | },{ 19 | params: [{ 20 | name: 'SomeEvent', 21 | type: 'event', 22 | inputs: [{ 23 | type: 'bytes', 24 | name: 'somebytes' 25 | },{ 26 | type: 'byte16', 27 | name: 'myBytes' 28 | }] 29 | }], 30 | result: '0xab132b6cdd50f8d4d2ea33c3f140a9b3cf40f451540c69765c4842508bb13838' 31 | },{ 32 | params: [{ 33 | name: 'AnotherEvent', 34 | type: 'event', 35 | inputs: [] 36 | }], 37 | result: '0x601d819e31a3cd164f83f7a7cf9cb5042ab1acff87b773c68f63d059c0af2dc0' 38 | }]; 39 | 40 | describe('encodeEventSignature', function () { 41 | tests.forEach(function (test) { 42 | it('should convert correctly', function () { 43 | assert.equal(Abi.encodeEventSignature.apply(Abi, test.params), test.result); 44 | }); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /test/eth.abi.encodeParameter.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Abi = require('../packages/web3-eth-abi'); 4 | 5 | var tests = [{ 6 | params: ['uint256', '2345675643'], 7 | result: '0x000000000000000000000000000000000000000000000000000000008bd02b7b' 8 | },{ 9 | params: ['bytes32', '0xdf3234'], 10 | result: '0xdf32340000000000000000000000000000000000000000000000000000000000' 11 | },{ 12 | params: ['bytes32[]', ['0xdf3234', '0xfdfd']], 13 | result: '0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002df32340000000000000000000000000000000000000000000000000000000000fdfd000000000000000000000000000000000000000000000000000000000000' 14 | }]; 15 | 16 | describe('encodeParameter', function () { 17 | tests.forEach(function (test) { 18 | it('should convert correctly', function () { 19 | assert.equal(Abi.encodeParameter.apply(Abi, test.params), test.result); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /test/eth.accounts.create.js: -------------------------------------------------------------------------------- 1 | var Accounts = require("./../packages/web3-eth-accounts"); 2 | var ethers = require('ethers'); 3 | var chai = require('chai'); 4 | var assert = chai.assert; 5 | var Web3 = require('../packages/web3'); 6 | var web3 = new Web3(); 7 | 8 | var tests = []; 9 | for (var i = 0; i < 1000; i++) { 10 | tests.push(i); 11 | } 12 | 13 | 14 | describe("eth", function () { 15 | describe("accounts", function () { 16 | 17 | tests.forEach(function (test, i) { 18 | it("create eth.account, and compare to ethers wallet", function() { 19 | var ethAccounts = new Accounts(); 20 | 21 | // create account 22 | var acc = ethAccounts.create(); 23 | 24 | // create ethers wallet 25 | var ethWall = new ethers.Wallet(acc.privateKey); 26 | 27 | // compare addresses and private keys 28 | assert.equal(acc.address, ethWall.address); 29 | assert.equal(acc.privateKey, ethWall.privateKey); 30 | }); 31 | 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /test/eth.call.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'call'; 4 | 5 | var tests = [{ 6 | args: [{ 7 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 8 | data: '0x23455654', 9 | gas: 11, 10 | gasPrice: 11 11 | }], 12 | formattedArgs: [{ 13 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 14 | data: '0x23455654', 15 | gas: '0xb', 16 | gasPrice: '0xb' 17 | }, 'latest'], 18 | result: '0x31981', 19 | formattedResult: '0x31981', 20 | call: 'eth_'+ method 21 | },{ 22 | args: [{ 23 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 24 | data: '0x23455654', 25 | gas: 11, 26 | gasPrice: 11 27 | }, 11], 28 | formattedArgs: [{ 29 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 30 | data: '0x23455654', 31 | gas: '0xb', 32 | gasPrice: '0xb' 33 | }, '0xb'], 34 | result: '0x31981', 35 | formattedResult: '0x31981', 36 | call: 'eth_'+ method 37 | }]; 38 | 39 | testMethod.runTests('eth', method, tests); 40 | 41 | -------------------------------------------------------------------------------- /test/eth.defaultBlock.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Eth = require('../packages/web3-eth'); 4 | 5 | var eth = new Eth(); 6 | 7 | var setValue = 123; 8 | 9 | describe('web3.eth', function () { 10 | describe('defaultBlock', function () { 11 | it('should check if defaultBlock is set to proper value', function () { 12 | assert.equal(eth.defaultBlock, 'latest'); 13 | assert.equal(eth.personal.defaultBlock, 'latest'); 14 | assert.equal(eth.Contract.defaultBlock, 'latest'); 15 | assert.equal(eth.getCode.method.defaultBlock, 'latest'); 16 | }); 17 | it('should set defaultBlock for all sub packages is set to proper value, if Eth package is changed', function () { 18 | eth.defaultBlock = setValue; 19 | 20 | assert.equal(eth.defaultBlock, setValue); 21 | assert.equal(eth.personal.defaultBlock, setValue); 22 | assert.equal(eth.Contract.defaultBlock, setValue); 23 | assert.equal(eth.getCode.method.defaultBlock, setValue); 24 | }); 25 | }); 26 | }); 27 | 28 | -------------------------------------------------------------------------------- /test/eth.estimateGas.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'estimateGas'; 4 | 5 | var tests = [{ 6 | args: [{ 7 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 8 | data: '0x23455654', 9 | gas: 11, 10 | gasPrice: 11 11 | }], 12 | formattedArgs: [{ 13 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 14 | data: '0x23455654', 15 | gas: '0xb', 16 | gasPrice: '0xb' 17 | }], 18 | result: '0x31981', 19 | formattedResult: 203137, 20 | call: 'eth_'+ method 21 | }]; 22 | 23 | testMethod.runTests('eth', method, tests); 24 | 25 | -------------------------------------------------------------------------------- /test/eth.gasPrice.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getGasPrice'; 4 | var methodCall = 'eth_gasPrice'; 5 | 6 | var tests = [{ 7 | result: '0x15f90', 8 | formattedResult: '90000', 9 | call: methodCall 10 | }]; 11 | 12 | 13 | testMethod.runTests('eth', method, tests); 14 | 15 | -------------------------------------------------------------------------------- /test/eth.getAccounts.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getAccounts'; 4 | var call = 'eth_accounts'; 5 | 6 | var tests = [{ 7 | result: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae'], 8 | formattedResult: ['0x47D33b27Bb249a2DBab4C0612BF9CaF4C1950855', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'], 9 | call: call 10 | }, 11 | { 12 | result: ['0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'], 13 | formattedResult: ['0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'], 14 | call: call 15 | }]; 16 | 17 | 18 | testMethod.runTests('eth', method, tests); 19 | 20 | -------------------------------------------------------------------------------- /test/eth.getBlockNumber.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getBlockNumber'; 4 | 5 | var tests = [{ 6 | result: '0xb', 7 | formattedResult: 11, 8 | call: 'eth_blockNumber' 9 | }]; 10 | 11 | 12 | testMethod.runTests('eth', method, tests); 13 | -------------------------------------------------------------------------------- /test/eth.getBlockTransactionCount.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getBlockTransactionCount'; 4 | 5 | 6 | var tests = [{ 7 | args: ['0x4e65fda2159562a496f9f3522f8922f89122a3088497a122a3088497a'], 8 | formattedArgs: ['0x4e65fda2159562a496f9f3522f8922f89122a3088497a122a3088497a'], 9 | result: '0xb', 10 | formattedResult: 11, 11 | call: 'eth_getBlockTransactionCountByHash' 12 | },{ 13 | args: ['0x47D33b27Bb249a2DBab4C0612BF9CaF4C1950855'], 14 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 15 | result: '0xb', 16 | formattedResult: 11, 17 | call: 'eth_getBlockTransactionCountByHash' 18 | },{ 19 | args: [436], 20 | formattedArgs: ['0x1b4'], 21 | result: '0xb', 22 | formattedResult: 11, 23 | call: 'eth_getBlockTransactionCountByNumber' 24 | },{ 25 | args: ['pending'], 26 | formattedArgs: ['pending'], 27 | result: '0xb', 28 | formattedResult: 11, 29 | call: 'eth_getBlockTransactionCountByNumber' 30 | }]; 31 | 32 | testMethod.runTests('eth', method, tests); 33 | 34 | -------------------------------------------------------------------------------- /test/eth.getBlockUncleCount.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getBlockUncleCount'; 4 | 5 | var tests = [{ 6 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 7 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 8 | result: '0xb', 9 | formattedResult: 11, 10 | call: 'eth_getUncleCountByBlockHash' 11 | },{ 12 | args: [436], 13 | formattedArgs: ['0x1b4'], 14 | result: '0xb', 15 | formattedResult: 11, 16 | call: 'eth_getUncleCountByBlockNumber' 17 | },{ 18 | args: ['pending'], 19 | formattedArgs: ['pending'], 20 | result: '0xb', 21 | formattedResult: 11, 22 | call: 'eth_getUncleCountByBlockNumber' 23 | }]; 24 | 25 | testMethod.runTests('eth', method, tests); 26 | -------------------------------------------------------------------------------- /test/eth.getChainId.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getChainId'; 4 | var methodCall = 'eth_chainId'; 5 | 6 | var tests = [{ 7 | result: '0x01', 8 | formattedResult: 1, 9 | call: methodCall 10 | }]; 11 | 12 | 13 | testMethod.runTests('eth', method, tests); 14 | 15 | -------------------------------------------------------------------------------- /test/eth.getCoinbase.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getCoinbase'; 4 | 5 | 6 | var tests = [{ 7 | result: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 8 | formattedResult: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 9 | call: 'eth_coinbase' 10 | }]; 11 | 12 | 13 | testMethod.runTests('eth', method, tests); 14 | -------------------------------------------------------------------------------- /test/eth.getHashRate.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getHashrate'; 4 | 5 | 6 | var tests = [{ 7 | result: '0x788a8', 8 | formattedResult: 493736, 9 | call: 'eth_hashrate' 10 | }]; 11 | 12 | 13 | testMethod.runTests('eth', method, tests); 14 | 15 | -------------------------------------------------------------------------------- /test/eth.getNodeVersion.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getNodeInfo'; 4 | var call = 'web3_clientVersion'; 5 | 6 | var tests = [{ 7 | result: 'Geth/v1.6.7-stable-ab5646c5/darwin-amd64/go1.8.3', 8 | formattedResult: 'Geth/v1.6.7-stable-ab5646c5/darwin-amd64/go1.8.3', 9 | call: call 10 | }]; 11 | 12 | 13 | testMethod.runTests('eth', method, tests); 14 | -------------------------------------------------------------------------------- /test/eth.getWork.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getWork'; 4 | 5 | var tests = [{ 6 | args: [], 7 | formattedArgs: [], 8 | result: true, 9 | formattedResult: true, 10 | call: 'eth_'+ method 11 | }]; 12 | 13 | testMethod.runTests('eth', method, tests); 14 | 15 | -------------------------------------------------------------------------------- /test/eth.handleRevert.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Eth = require('../packages/web3-eth'); 4 | 5 | var eth = new Eth(); 6 | 7 | var setValue = true; 8 | 9 | describe('web3.eth', function () { 10 | describe('handleRevert', function () { 11 | it('should check if handleRevert is set to proper value', function () { 12 | assert.equal(eth.handleRevert, false); 13 | assert.equal(eth.Contract.handleRevert, false); 14 | assert.equal(eth.getCode.method.handleRevert, false); 15 | }); 16 | 17 | it('should set handleRevert for all sub packages', function () { 18 | eth.handleRevert = setValue; 19 | 20 | assert.equal(eth.handleRevert, setValue); 21 | assert.equal(eth.Contract.handleRevert, setValue); 22 | assert.equal(eth.getCode.method.handleRevert, setValue); 23 | }); 24 | }); 25 | }); 26 | 27 | -------------------------------------------------------------------------------- /test/eth.isMining.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'isMining'; 4 | var call = 'eth_mining'; 5 | 6 | var tests = [{ 7 | result: true, 8 | formattedResult: true, 9 | call: call 10 | }]; 11 | 12 | 13 | testMethod.runTests('eth', method, tests); 14 | -------------------------------------------------------------------------------- /test/eth.maxListenersWarningThreshold.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Eth = require('../packages/web3-eth'); 4 | 5 | var setValue = 123; 6 | 7 | describe('web3.eth', function () { 8 | describe('maxListenersWarningThreshold', function () { 9 | var eth; 10 | 11 | beforeEach(function (){ 12 | eth = new Eth(); 13 | }) 14 | it('should default to 100', function () { 15 | assert.equal(eth.maxListenersWarningThreshold, 100); 16 | }); 17 | it('should set threshold to proper value', function () { 18 | // Mock EventEmitter interface 19 | eth.currentProvider = { 20 | setMaxListeners: () => {} 21 | } 22 | eth.maxListenersWarningThreshold = setValue; 23 | assert.equal(eth.maxListenersWarningThreshold, setValue); 24 | }); 25 | it('should *NOT* set threshold when there is no currentProvider', function () { 26 | eth.maxListenersWarningThreshold = setValue; 27 | assert.equal(eth.maxListenersWarningThreshold, 100); 28 | }); 29 | it('should *NOT* set threshold when currentProvider does not extend EventEmitter', function () { 30 | eth.currentProvider = {} 31 | eth.maxListenersWarningThreshold = setValue; 32 | assert.equal(eth.maxListenersWarningThreshold, 100); 33 | }); 34 | }); 35 | }); 36 | 37 | -------------------------------------------------------------------------------- /test/eth.net.getPeerCount.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getPeerCount'; 4 | 5 | 6 | var tests = [{ 7 | result: '0xf', 8 | formattedResult: 15, 9 | call: 'net_peerCount' 10 | }]; 11 | 12 | testMethod.runTests(['eth','net'], method, tests); 13 | -------------------------------------------------------------------------------- /test/eth.net.isListening.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'isListening'; 4 | 5 | 6 | var tests = [{ 7 | result: true, 8 | formattedResult: true, 9 | call: 'net_listening' 10 | }]; 11 | 12 | testMethod.runTests(['eth','net'], method, tests); 13 | -------------------------------------------------------------------------------- /test/eth.net_methods.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var u = require('./helpers/test.utils.js'); 4 | var Eth = require('../packages/web3-eth'); 5 | var eth = new Eth(); 6 | 7 | describe('web3.net', function() { 8 | describe('methods', function() { 9 | u.methodExists(eth.net, 'getId'); 10 | u.methodExists(eth.net, 'getNetworkType'); 11 | u.methodExists(eth.net, 'isListening'); 12 | u.methodExists(eth.net, 'getPeerCount'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /test/eth.protocolVersion.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getProtocolVersion'; 4 | var call = 'eth_protocolVersion'; 5 | 6 | var tests = [{ 7 | result: '12345', 8 | formattedResult: '12345', 9 | call: call 10 | }]; 11 | 12 | 13 | testMethod.runTests('eth', method, tests); 14 | -------------------------------------------------------------------------------- /test/eth.requestAccounts.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'requestAccounts'; 4 | var call = 'eth_requestAccounts'; 5 | 6 | var tests = [{ 7 | result: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae'], 8 | formattedResult: ['0x47D33b27Bb249a2DBab4C0612BF9CaF4C1950855', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'], 9 | call: call 10 | }, 11 | { 12 | result: ['0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'], 13 | formattedResult: ['0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'], 14 | call: call 15 | }]; 16 | 17 | 18 | testMethod.runTests('eth', method, tests); 19 | 20 | -------------------------------------------------------------------------------- /test/eth.submitWork.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'submitWork'; 4 | 5 | var tests = [ 6 | { 7 | args: ['0x567890abcdef5555', '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', '0xcdef1234567890abcdef1234567890abcdef0x1234567890abcf1234567890ab'], 8 | formattedArgs: ['0x567890abcdef5555', '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', '0xcdef1234567890abcdef1234567890abcdef0x1234567890abcf1234567890ab'], 9 | result: true, 10 | formattedResult: true, 11 | call: 'eth_'+ method 12 | }]; 13 | 14 | testMethod.runTests('eth', method, tests); 15 | 16 | -------------------------------------------------------------------------------- /test/eth.transactionBlockTimeout.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Eth = require('../packages/web3-eth'); 4 | 5 | var eth = new Eth(); 6 | 7 | var setValue = 123; 8 | 9 | describe('web3.eth', function () { 10 | describe('transactionBlockTimeout', function () { 11 | it('should check if transactionBlockTimeout is set to proper value', function () { 12 | assert.equal(eth.transactionBlockTimeout, 50); 13 | assert.equal(eth.Contract.transactionBlockTimeout, 50); 14 | assert.equal(eth.getCode.method.transactionBlockTimeout, 50); 15 | }); 16 | it('should set transactionBlockTimeout for all sub packages is set to proper value, if Eth package is changed', function () { 17 | eth.transactionBlockTimeout = setValue; 18 | 19 | assert.equal(eth.transactionBlockTimeout, setValue); 20 | assert.equal(eth.Contract.transactionBlockTimeout, setValue); 21 | assert.equal(eth.getCode.method.transactionBlockTimeout, setValue); 22 | }); 23 | }); 24 | }); 25 | 26 | -------------------------------------------------------------------------------- /test/eth.transactionConfirmationBlocks.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Eth = require('../packages/web3-eth'); 4 | 5 | var eth = new Eth(); 6 | 7 | var setValue = 123; 8 | 9 | describe('web3.eth', function () { 10 | describe('transactionConfirmationBlocks', function () { 11 | it('should check if transactionConfirmationBlocks is set to proper value', function () { 12 | assert.equal(eth.transactionConfirmationBlocks, 24); 13 | assert.equal(eth.Contract.transactionConfirmationBlocks, 24); 14 | assert.equal(eth.getCode.method.transactionConfirmationBlocks, 24); 15 | }); 16 | it('should set transactionConfirmationBlocks for all sub packages is set to proper value, if Eth package is changed', function () { 17 | eth.transactionConfirmationBlocks = setValue; 18 | 19 | assert.equal(eth.transactionConfirmationBlocks, setValue); 20 | assert.equal(eth.Contract.transactionConfirmationBlocks, setValue); 21 | assert.equal(eth.getCode.method.transactionConfirmationBlocks, setValue); 22 | }); 23 | }); 24 | }); 25 | 26 | -------------------------------------------------------------------------------- /test/eth.transactionPollingTimeout.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Eth = require('../packages/web3-eth'); 4 | 5 | var eth = new Eth(); 6 | 7 | var setValue = 123; 8 | 9 | describe('web3.eth', function () { 10 | describe('transactionPollingTimeout', function () { 11 | it('should check if transactionPollingTimeout is set to proper value', function () { 12 | assert.equal(eth.transactionPollingTimeout, 750); 13 | assert.equal(eth.Contract.transactionPollingTimeout, 750); 14 | assert.equal(eth.getCode.method.transactionPollingTimeout, 750); 15 | }); 16 | it('should set transactionPollingTimeout for all sub packages is set to proper value, if Eth package is changed', function () { 17 | eth.transactionPollingTimeout = setValue; 18 | 19 | assert.equal(eth.transactionPollingTimeout, setValue); 20 | assert.equal(eth.Contract.transactionPollingTimeout, setValue); 21 | assert.equal(eth.getCode.method.transactionPollingTimeout, setValue); 22 | }); 23 | }); 24 | }); 25 | 26 | -------------------------------------------------------------------------------- /test/formatters.inputDefaultBlockFormatter.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var formatters = require('../packages/web3-core-helpers/src/formatters.js'); 4 | 5 | var tests = [ 6 | { value: 'genesis', expected: '0x0' }, 7 | { value: 'latest', expected: 'latest' }, 8 | { value: 'pending', expected: 'pending' }, 9 | { value: 'earliest', expected: 'earliest' }, 10 | { value: 1, expected: '0x1' }, 11 | { value: '0x1', expected: '0x1' } 12 | ]; 13 | 14 | describe('lib/web3/formatters', function () { 15 | describe('inputDefaultBlockNumberFormatter', function () { 16 | tests.forEach(function (test) { 17 | it('should turn ' + test.value + ' to ' + test.expected, function () { 18 | assert.strictEqual(formatters.inputDefaultBlockNumberFormatter(test.value), test.expected); 19 | }); 20 | }); 21 | }); 22 | }); 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /test/formatters.inputPostFormatter.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var formatters = require('../packages/web3-core-helpers/src/formatters.js'); 4 | 5 | describe('formatters', function () { 6 | describe('inputPostFormatter', function () { 7 | it('should return the correct value', function () { 8 | 9 | // input as strings and numbers 10 | assert.deepEqual(formatters.inputPostFormatter({ 11 | from: '0x00000', 12 | to: '0x00000', 13 | payload: '0x7b2274657374223a2274657374227d',//{test: 'test'}, 14 | ttl: 200, 15 | priority: 1000, 16 | topics: ['hello','mytopics'], 17 | "workToProve": 1 18 | }), { 19 | from: '0x00000', 20 | to: '0x00000', 21 | payload: '0x7b2274657374223a2274657374227d', 22 | ttl: '0xc8', 23 | priority: '0x3e8', 24 | topics: ['0x68656c6c6f','0x6d79746f70696373'], 25 | workToProve: '0x1' 26 | }); 27 | 28 | }); 29 | }); 30 | }); 31 | 32 | -------------------------------------------------------------------------------- /test/formatters.outputPostFormatter.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var formatters = require('../packages/web3-core-helpers/src/formatters.js'); 3 | 4 | describe('formatters', function () { 5 | describe('outputPostFormatter', function () { 6 | it('should return the correct value', function () { 7 | 8 | assert.deepEqual(formatters.outputPostFormatter({ 9 | expiry: '0x3e8', 10 | sent: '0x3e8', 11 | ttl: '0x3e8', 12 | workProved: '0x3e8', 13 | payload: '0x7b2274657374223a2274657374227d', 14 | topics: ['0x68656c6c6f','0x6d79746f70696373'] 15 | }), { 16 | expiry: 1000, 17 | sent: 1000, 18 | ttl: 1000, 19 | workProved: 1000, 20 | payload: '0x7b2274657374223a2274657374227d', //{test: 'test'}, 21 | // payloadRaw: '0x7b2274657374223a2274657374227d', 22 | topics: ['hello','mytopics'] 23 | }); 24 | }); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /test/helpers/FakeIpcProvider2.js: -------------------------------------------------------------------------------- 1 | var FakeHttpProvider = require('./FakeIpcProvider'); 2 | 3 | var FakeIpcProvider2 = function () { 4 | this.counter = 0; 5 | this.resultList = []; 6 | }; 7 | 8 | FakeIpcProvider2.prototype = new FakeHttpProvider(); 9 | FakeIpcProvider2.prototype.constructor = FakeIpcProvider2; 10 | 11 | FakeIpcProvider2.prototype.injectResultList = function (list) { 12 | this.resultList = list; 13 | }; 14 | 15 | FakeIpcProvider2.prototype.getResponse = function () { 16 | var result = this.resultList[this.counter]; 17 | this.counter++; 18 | 19 | // add fallback result value 20 | if(!result) 21 | result = { 22 | result: undefined 23 | }; 24 | 25 | if (result.type === 'batch') { 26 | this.injectBatchResults(result.result); 27 | } else { 28 | this.injectResult(result.result); 29 | } 30 | 31 | this.counter = 0; 32 | 33 | return this.response; 34 | }; 35 | 36 | module.exports = FakeIpcProvider2; 37 | 38 | -------------------------------------------------------------------------------- /test/helpers/FakeIpcRequest.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | 4 | var FakeIpcRequest = function () { 5 | var _this = this; 6 | this._handle = {fd: {}}; 7 | this.listenerList = []; 8 | 9 | return this; 10 | }; 11 | 12 | FakeIpcRequest.prototype.connect = function (path) { 13 | assert.notEqual(path, undefined); 14 | 15 | return this; 16 | }; 17 | 18 | 19 | FakeIpcRequest.prototype.on = function (name, callback) { 20 | if(name === 'data'){ 21 | this.listenerList.push(callback); 22 | } 23 | }; 24 | 25 | 26 | FakeIpcRequest.prototype.writeSync = function (payload) { 27 | assert.equal(typeof payload, 'string'); 28 | return payload; 29 | }; 30 | 31 | FakeIpcRequest.prototype.write = function (payload) { 32 | assert.equal(typeof payload, 'string'); 33 | 34 | this.listenerList.forEach(function(cb){ 35 | setTimeout(function(){ 36 | cb(payload); 37 | }, 100); 38 | }); 39 | 40 | }; 41 | 42 | module.exports = FakeIpcRequest; 43 | 44 | -------------------------------------------------------------------------------- /test/helpers/FakeXHR2.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | 4 | 5 | var FakeXHR2 = function () { 6 | this.responseText = undefined; 7 | this.readyState = 4; 8 | this.onreadystatechange = null; 9 | this.async = true; 10 | this.agents = {}; 11 | this.headers = { 12 | 'Content-Type': 'text/plain' 13 | }; 14 | }; 15 | 16 | FakeXHR2.prototype.nodejsSet = function (agents) { 17 | this.agents = agents; 18 | }; 19 | 20 | FakeXHR2.prototype.open = function (method, host, async) { 21 | assert.equal(method, 'POST'); 22 | assert.notEqual(host, null); 23 | this.async = async; 24 | }; 25 | 26 | FakeXHR2.prototype.setRequestHeader = function(name, value) { 27 | this.headers[name] = value; 28 | }; 29 | 30 | FakeXHR2.prototype.send = function (payload) { 31 | 32 | this.responseText = payload; 33 | 34 | assert.equal(typeof payload, 'string'); 35 | if (this.async) { 36 | assert.equal(typeof this.onreadystatechange, 'function'); 37 | this.onreadystatechange(); 38 | } 39 | }; 40 | 41 | module.exports = {XMLHttpRequest: FakeXHR2}; 42 | -------------------------------------------------------------------------------- /test/iban.createIndirect.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Iban = require('../packages/web3-eth-iban'); 4 | 5 | var tests = [ 6 | { institution: 'XREG', identifier: 'GAVOFYORK', expected: 'XE81ETHXREGGAVOFYORK'} 7 | ]; 8 | 9 | describe('lib/web3/iban', function () { 10 | describe('createIndirect', function () { 11 | tests.forEach(function (test) { 12 | it('shoud create indirect iban: ' + test.expected, function () { 13 | assert.deepEqual(Iban.createIndirect({ 14 | institution: test.institution, 15 | identifier: test.identifier 16 | }), new Iban(test.expected)); 17 | }); 18 | }); 19 | }); 20 | }); 21 | 22 | -------------------------------------------------------------------------------- /test/iban.fromAddress.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Iban = require('../packages/web3-eth-iban'); 4 | 5 | var tests = [ 6 | { address: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'}, 7 | { address: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'}, 8 | { address: '0x11c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE1222Q908LN1QBBU6XUQSO1OHWJIOS46OO'}, 9 | { address: '0x52dc504a422f0e2a9e7632a34a50f1a82f8224c7', expected: 'XE499OG1EH8ZZI0KXC6N83EKGT1BM97P2O7'}, 10 | { address: '0x0000a5327eab78357cbf2ae8f3d49fd9d90c7d22', expected: 'XE0600DQK33XDTYUCRI0KYM5ELAKXDWWF6'} 11 | ]; 12 | 13 | describe('lib/web3/iban', function () { 14 | describe('fromAddress', function () { 15 | tests.forEach(function (test) { 16 | it('shoud create indirect iban: ' + test.expected, function () { 17 | assert.deepEqual(Iban.fromAddress(test.address), new Iban(test.expected)); 18 | }); 19 | }); 20 | }); 21 | }); 22 | 23 | -------------------------------------------------------------------------------- /test/iban.isValid.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Iban = require('../packages/web3-eth-iban'); 4 | 5 | var tests = [ 6 | { obj: function () {}, is: false}, 7 | { obj: new Function(), is: false}, 8 | { obj: 'function', is: false}, 9 | { obj: {}, is: false}, 10 | { obj: '[]', is: false}, 11 | { obj: '[1, 2]', is: false}, 12 | { obj: '{}', is: false}, 13 | { obj: '{"a": 123, "b" :3,}', is: false}, 14 | { obj: '{"c" : 2}', is: false}, 15 | { obj: 'XE81ETHXREGGAVOFYORK', is: true}, 16 | { obj: 'XE82ETHXREGGAVOFYORK', is: false}, // control number is invalid 17 | { obj: 'XE81ETCXREGGAVOFYORK', is: false}, 18 | { obj: 'XE81ETHXREGGAVOFYORKD', is: false}, 19 | { obj: 'XE81ETHXREGGaVOFYORK', is: false}, 20 | { obj: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: true}, 21 | { obj: 'XE7438O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: false}, // control number is invalid 22 | { obj: 'XD7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: false}, 23 | { obj: 'XE1222Q908LN1QBBU6XUQSO1OHWJIOS46OO', is: true} 24 | ]; 25 | 26 | describe('lib/web3/iban', function () { 27 | describe('isValid', function () { 28 | tests.forEach(function (test) { 29 | it('shoud test if value ' + test.obj + ' is iban: ' + test.is, function () { 30 | assert.equal(Iban.isValid(test.obj), test.is); 31 | }); 32 | }); 33 | }); 34 | }); 35 | 36 | -------------------------------------------------------------------------------- /test/iban.toAddress.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Iban = require('../packages/web3-eth-iban'); 4 | 5 | var tests = [ 6 | { direct: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', address: '0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8'} 7 | ]; 8 | 9 | describe('lib/web3/iban', function () { 10 | describe('Iban.toAddress()', function () { 11 | tests.forEach(function (test) { 12 | it('shoud transform iban to address: ' + test.address, function () { 13 | assert.deepEqual(Iban.toAddress(test.direct), test.address); 14 | }); 15 | }); 16 | }); 17 | describe('iban instance address()', function () { 18 | tests.forEach(function (test) { 19 | it('shoud transform iban to address: ' + test.address, function () { 20 | var iban = new Iban(test.direct); 21 | assert.deepEqual(iban.toAddress(), test.address); 22 | }); 23 | }); 24 | }); 25 | }); 26 | 27 | -------------------------------------------------------------------------------- /test/iban.toIban.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Iban = require('../packages/web3-eth-iban'); 4 | 5 | var tests = [ 6 | { address: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'}, 7 | { address: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'}, 8 | { address: '0x11c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE1222Q908LN1QBBU6XUQSO1OHWJIOS46OO'}, 9 | { address: '0x52dc504a422f0e2a9e7632a34a50f1a82f8224c7', expected: 'XE499OG1EH8ZZI0KXC6N83EKGT1BM97P2O7'}, 10 | { address: '0x0000a5327eab78357cbf2ae8f3d49fd9d90c7d22', expected: 'XE0600DQK33XDTYUCRI0KYM5ELAKXDWWF6'} 11 | ]; 12 | 13 | describe('lib/web3/iban', function () { 14 | describe('fromAddress', function () { 15 | tests.forEach(function (test) { 16 | it('shoud create indirect iban: ' + test.expected, function () { 17 | assert.deepEqual(Iban.toIban(test.address), test.expected); 18 | }); 19 | }); 20 | }); 21 | }); 22 | 23 | -------------------------------------------------------------------------------- /test/jsonrpc.id.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Jsonrpc = require('../packages/web3-core-requestmanager/src/jsonrpc'); 4 | 5 | describe('lib/web3/jsonrpc', function () { 6 | describe('id', function () { 7 | it('should increment the id', function () { 8 | 9 | // given 10 | var method = 'm'; 11 | 12 | // when 13 | var p1 = Jsonrpc.toPayload(method); 14 | var p2 = Jsonrpc.toPayload(method); 15 | 16 | // then 17 | assert.equal(p2.id, p1.id + 1); 18 | }); 19 | }); 20 | }); 21 | 22 | -------------------------------------------------------------------------------- /test/method.formatInput.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Method = require('../packages/web3-core-method'); 4 | 5 | describe('lib/web3/method', function () { 6 | describe('formatInput', function () { 7 | it('should format plain input', function () { 8 | 9 | // given 10 | var star = function (arg) { 11 | return arg + '*'; 12 | }; 13 | 14 | var method = new Method({ 15 | name: 'something', call: 'eth_something', 16 | inputFormatter: [star, star, star] 17 | }); 18 | var args = ['1','2','3']; 19 | var expectedArgs = ['1*', '2*', '3*']; 20 | 21 | // when 22 | var result = method.formatInput(args); 23 | 24 | // then 25 | assert.deepEqual(result, expectedArgs); 26 | }); 27 | 28 | it('should do nothing if there is no formatter', function () { 29 | 30 | // given 31 | var method = new Method({name: 'something', call: 'eth_something'}); 32 | var args = [1,2,3]; 33 | 34 | // when 35 | var result = method.formatInput(args); 36 | 37 | // then 38 | assert.deepEqual(result, args); 39 | }); 40 | }); 41 | }); 42 | 43 | -------------------------------------------------------------------------------- /test/method.getCall.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Method = require('../packages/web3-core-method'); 4 | 5 | describe('lib/web3/method', function () { 6 | describe('getCall', function () { 7 | it('should return call name', function () { 8 | 9 | // given 10 | var call = 'hello_call_world'; 11 | var method = new Method({ 12 | name: 'something', 13 | call: call 14 | }); 15 | 16 | // when 17 | var result = method.getCall(); 18 | 19 | // then 20 | assert.equal(call, result); 21 | }); 22 | 23 | it('should return call based on args', function () { 24 | 25 | // given 26 | var call = function (args) { 27 | return args ? args.length.toString() : '0'; 28 | }; 29 | 30 | var method = new Method({ 31 | name: 'something', 32 | call: call 33 | }); 34 | 35 | // when 36 | var r0 = method.getCall(); 37 | var r1 = method.getCall([1]); 38 | var r2 = method.getCall([1, 2]); 39 | 40 | // then 41 | assert.equal(r0, '0'); 42 | assert.equal(r1, '1'); 43 | assert.equal(r2, '2'); 44 | 45 | }); 46 | }); 47 | }); 48 | 49 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter dot 2 | -------------------------------------------------------------------------------- /test/personal.getAccounts.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getAccounts'; 4 | 5 | 6 | var tests = [{ 7 | result: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 8 | formattedResult: ['0x47D33b27Bb249a2DBab4C0612BF9CaF4C1950855'], // checksum address 9 | call: 'personal_listAccounts' 10 | }]; 11 | 12 | testMethod.runTests(['eth','personal'], method, tests); 13 | -------------------------------------------------------------------------------- /test/personal.lockAccount.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'lockAccount'; 4 | 5 | 6 | var tests = [{ 7 | args: ['0x47D33b27Bb249a2DBab4C0612BF9CaF4C1950855'], // checksum address 8 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 9 | result: true, 10 | formattedResult: true, 11 | call: 'personal_'+ method 12 | },{ 13 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 14 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 15 | result: true, 16 | formattedResult: true, 17 | call: 'personal_'+ method 18 | }]; 19 | 20 | testMethod.runTests(['eth','personal'], method, tests); 21 | -------------------------------------------------------------------------------- /test/personal.newAccount.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'newAccount'; 4 | 5 | 6 | var tests = [{ 7 | args: ['P@ssw0rd!'], 8 | formattedArgs: ['P@ssw0rd!'], 9 | result: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 10 | formattedResult: ['0x47D33b27Bb249a2DBab4C0612BF9CaF4C1950855'], // checksum address 11 | call: 'personal_newAccount' 12 | }]; 13 | 14 | testMethod.runTests(['eth','personal'], method, tests); 15 | 16 | -------------------------------------------------------------------------------- /test/personal.unlockAccount.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'unlockAccount'; 4 | 5 | 6 | var tests = [{ 7 | args: ['0x47D33b27Bb249a2DBab4C0612BF9CaF4C1950855', 'P@ssw0rd!'], // checksum address 8 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 'P@ssw0rd!', null], 9 | result: true, 10 | formattedResult: true, 11 | call: 'personal_'+ method 12 | },{ 13 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 'P@ssw0rd!', 10], 14 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 'P@ssw0rd!', 10], 15 | result: true, 16 | formattedResult: true, 17 | call: 'personal_'+ method 18 | }]; 19 | 20 | testMethod.runTests(['eth','personal'], method, tests); 21 | -------------------------------------------------------------------------------- /test/personal_methods.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var u = require('./helpers/test.utils.js'); 4 | var Personal = require('../packages/web3-eth-personal'); 5 | var personal = new Personal(); 6 | 7 | describe('web3.net', function() { 8 | describe('methods', function() { 9 | u.methodExists(personal, 'getAccounts'); 10 | u.methodExists(personal, 'newAccount'); 11 | u.methodExists(personal, 'unlockAccount'); 12 | u.methodExists(personal, 'lockAccount'); 13 | u.methodExists(personal, 'sendTransaction'); 14 | 15 | u.propertyExists(personal, 'net'); 16 | u.methodExists(personal.net, 'getId'); 17 | u.methodExists(personal.net, 'isListening'); 18 | u.methodExists(personal.net, 'getPeerCount'); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /test/requestmanager.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var FakeHttpProvider = require('./helpers/FakeIpcProvider'); 4 | var requestManager = require('../packages/web3-core-requestmanager'); 5 | 6 | // TODO: handling errors! 7 | // TODO: validation of params! 8 | 9 | describe('lib/web3/requestmanager', function () { 10 | describe('send', function () { 11 | it('should return expected result asynchronously', function (done) { 12 | var provider = new FakeHttpProvider(); 13 | var manager = new requestManager.Manager(provider); 14 | var expected = 'hello_world'; 15 | provider.injectResult(expected); 16 | 17 | manager.send({ 18 | method: 'test', 19 | params: [1,2,3] 20 | }, function (error, result) { 21 | assert.equal(error, null); 22 | assert.equal(expected, result); 23 | done(); 24 | }); 25 | }); 26 | }); 27 | }); 28 | 29 | -------------------------------------------------------------------------------- /test/shh.post.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var method = 'post'; 5 | 6 | var tests = [{ 7 | args: [{ 8 | symKeyID: '123123123ff', 9 | sig: '44ffdd55', 10 | topic: '0xffdd11', 11 | payload: utils.numberToHex('12345'), 12 | ttl: 100, 13 | minPow: 0.5, 14 | powTarget: 3, 15 | padding: '0xffdd4455' 16 | }], 17 | formattedArgs: [{ 18 | symKeyID: '123123123ff', 19 | sig: '44ffdd55', 20 | topic: '0xffdd11', 21 | payload: utils.numberToHex('12345'), 22 | ttl: 100, 23 | minPow: 0.5, 24 | powTarget: 3, 25 | padding: '0xffdd4455' 26 | }], 27 | result: true, 28 | formattedResult: true, 29 | call: 'shh_'+ method 30 | }]; 31 | 32 | testMethod.runTests('shh', method, tests); 33 | 34 | -------------------------------------------------------------------------------- /test/shh_methods.js: -------------------------------------------------------------------------------- 1 | var u = require('./helpers/test.utils.js'); 2 | var Shh = require('../packages/web3-shh'); 3 | var shh = new Shh(); 4 | 5 | describe('shh', function() { 6 | describe('methods', function() { 7 | u.methodExists(shh, 'subscribe'); 8 | 9 | u.methodExists(shh, 'getVersion'); 10 | u.methodExists(shh, 'getInfo'); 11 | u.methodExists(shh, 'setMaxMessageSize'); 12 | u.methodExists(shh, 'setMinPoW'); 13 | u.methodExists(shh, 'markTrustedPeer'); 14 | u.methodExists(shh, 'newKeyPair'); 15 | u.methodExists(shh, 'addPrivateKey'); 16 | u.methodExists(shh, 'deleteKeyPair'); 17 | u.methodExists(shh, 'hasKeyPair'); 18 | u.methodExists(shh, 'getPublicKey'); 19 | u.methodExists(shh, 'getPrivateKey'); 20 | u.methodExists(shh, 'newSymKey'); 21 | u.methodExists(shh, 'addSymKey'); 22 | u.methodExists(shh, 'generateSymKeyFromPassword'); 23 | u.methodExists(shh, 'hasSymKey'); 24 | u.methodExists(shh, 'getSymKey'); 25 | u.methodExists(shh, 'deleteSymKey'); 26 | u.methodExists(shh, 'newMessageFilter'); 27 | u.methodExists(shh, 'getFilterMessages'); 28 | u.methodExists(shh, 'deleteMessageFilter'); 29 | u.methodExists(shh, 'post'); 30 | }); 31 | }); 32 | 33 | -------------------------------------------------------------------------------- /test/sources/Basic.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * Source contract for Basic.json 3 | */ 4 | pragma solidity ^0.5.1; 5 | 6 | contract Basic { 7 | 8 | uint value; 9 | event BasicEvent(address addr, uint indexed val); 10 | event StringEvent(string str); 11 | event IndexedStringEvent(string str); 12 | 13 | function getValue() public view returns (uint val) { 14 | return value; 15 | } 16 | 17 | function setValue(uint _value) public { 18 | value = _value; 19 | } 20 | 21 | function requireWithoutReason() public { 22 | require(false); 23 | } 24 | 25 | function requireWithReason() public { 26 | require(false, 'REVERTED WITH REQUIRE'); 27 | } 28 | 29 | function reverts() public { 30 | revert('REVERTED WITH REVERT'); 31 | } 32 | 33 | function firesEvent(address addr, uint val) public { 34 | emit BasicEvent(addr, val); 35 | } 36 | 37 | function firesStringEvent(string memory _str) public { 38 | emit StringEvent(_str); 39 | } 40 | 41 | function firesIndexedStringEvent(string memory _str) public { 42 | emit IndexedStringEvent(_str); 43 | } 44 | 45 | function firesIllegalUtf8StringEvent() public { 46 | emit StringEvent('�������'); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/sources/Misc.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "Misc", 3 | "abi": [ 4 | { 5 | "inputs": [], 6 | "payable": false, 7 | "stateMutability": "nonpayable", 8 | "type": "constructor" 9 | } 10 | ], 11 | "bytecode": "0x6080604052348015600f57600080fd5b50603580601d6000396000f3fe6080604052600080fdfea165627a7a723058205b81906cade92d8eeda5d0627076490bd44b563a504fe790edbcd6afadbe359d0029", 12 | "deployedBytecode": "0x6080604052600080fdfea165627a7a723058205b81906cade92d8eeda5d0627076490bd44b563a504fe790edbcd6afadbe359d0029", 13 | "linkReferences": {}, 14 | "deployedLinkReferences": {} 15 | } 16 | -------------------------------------------------------------------------------- /test/sources/Misc.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.1; 2 | 3 | contract Misc { 4 | 5 | string misc; 6 | 7 | constructor() public { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/sources/Reverts.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "Reverts", 3 | "abi": [ 4 | { 5 | "inputs": [], 6 | "payable": false, 7 | "stateMutability": "nonpayable", 8 | "type": "constructor" 9 | } 10 | ], 11 | "bytecode": "0x6080604052348015600f57600080fd5b506000601a57600080fd5b603e8060276000396000f3fe6080604052600080fdfea265627a7a72315820fd31c994ac2f614e770a2ea9e63f6bc8f05f3e5aa1feb77ad79c3a778d594f4064736f6c634300050b0032", 12 | "deployedBytecode": "0x6080604052600080fdfea265627a7a72315820fd31c994ac2f614e770a2ea9e63f6bc8f05f3e5aa1feb77ad79c3a778d594f4064736f6c634300050b0032", 13 | "linkReferences": {}, 14 | "deployedLinkReferences": {} 15 | } 16 | -------------------------------------------------------------------------------- /test/sources/Reverts.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * Source contract for Reverts.json 3 | */ 4 | pragma solidity ^0.5.1; 5 | 6 | contract Reverts { 7 | 8 | constructor() public { 9 | require(false); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/utils.fromAscii.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: 'myString', expected: '0x6d79537472696e67'}, 8 | { value: 'myString\x00', expected: '0x6d79537472696e6700'}, 9 | { value: '\u0003\u0000\u0000\u00005èÆÕL]\u0012|Î¾ž\u001a7«›\u00052\u0011(ЗY\n<\u0010\u0000\u0000\u0000\u0000\u0000\u0000e!ßd/ñõì\f:z¦Î¦±ç·÷Í¢Ëß\u00076*…\bŽ—ñžùC1ÉUÀé2\u001aӆBŒ', 10 | expected: '0x0300000035e8c6d54c5d127c9dcebe9e1a37ab9b05321128d097590a3c100000000000006521df642ff1f5ec0c3a7aa6cea6b1e7b7f7cda2cbdf07362a85088e97f19ef94331c955c0e9321ad386428c'} 11 | ]; 12 | 13 | describe('lib/utils/utils', function () { 14 | describe('asciiToHex', function () { 15 | tests.forEach(function (test) { 16 | it('should turn ' + test.value + ' to ' + test.expected, function () { 17 | assert.strictEqual(utils.fromAscii(test.value), test.expected); 18 | }); 19 | }); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /test/utils.hexToNumber.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | describe('lib/utils/utils', function () { 5 | describe('hexToNumber', function () { 6 | it('should return the correct value', function () { 7 | 8 | assert.equal(utils.hexToNumber("0x3e8"), 1000); 9 | assert.equal(utils.hexToNumber('0x1f0fe294a36'), 2134567897654); 10 | // allow compatiblity 11 | assert.equal(utils.hexToNumber(100000), 100000); 12 | }); 13 | 14 | it('should validate hex strings', function() { 15 | try { 16 | utils.hexToNumber('100000'); 17 | assert.fail(); 18 | } catch (error){ 19 | assert(error.message.includes('is not a valid hex string')) 20 | } 21 | }) 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /test/utils.isAddress.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: function () {}, is: false}, 8 | { value: new Function(), is: false}, 9 | { value: 'function', is: false}, 10 | { value: {}, is: false}, 11 | { value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true }, 12 | { value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: true }, 13 | { value: '0xE247A45c287191d435A8a5D72A7C8dc030451E9F', is: true }, 14 | { value: '0xE247a45c287191d435A8a5D72A7C8dc030451E9F', is: false }, 15 | { value: '0xe247a45c287191d435a8a5d72a7c8dc030451e9f', is: true }, 16 | { value: '0xE247A45C287191D435A8A5D72A7C8DC030451E9F', is: true }, 17 | { value: '0XE247A45C287191D435A8A5D72A7C8DC030451E9F', is: true } 18 | ]; 19 | 20 | describe('lib/utils/utils', function () { 21 | describe('isAddress', function () { 22 | tests.forEach(function (test) { 23 | it('shoud test if value ' + test.value + ' is address: ' + test.is, function () { 24 | assert.equal(utils.isAddress(test.value), test.is); 25 | }); 26 | }); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /test/utils.isBN.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var BigNumber = require('bn.js'); 5 | 6 | var assert = chai.assert; 7 | 8 | var tests = [ 9 | { value: function () {}, is: false}, 10 | { value: new Function(), is: false}, 11 | { value: 'function', is: false}, 12 | { value: {}, is: false}, 13 | { value: new String('hello'), is: false}, 14 | { value: new BigNumber(0), is: true}, 15 | { value: 132, is: false}, 16 | { value: '0x12', is: false}, 17 | 18 | ]; 19 | 20 | describe('lib/utils/utils', function () { 21 | describe('isBigNumber', function () { 22 | tests.forEach(function (test) { 23 | it('shoud test if value ' + test.func + ' is BigNumber: ' + test.is, function () { 24 | assert.equal(utils.isBN(test.value), test.is); 25 | }); 26 | }); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /test/utils.isChecksumAddress.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: '0x52908400098527886E0F7030069857D2E4169EE7', is: true }, 8 | { value: '0x8617E340B3D01FA5F11F306F4090FD50E238070D', is: true }, 9 | { value: '0xde709f2102306220921060314715629080e2fb77', is: true }, 10 | { value: '0x27b1fdb04752bbc536007a920d24acb045561c26', is: true }, 11 | { value: '0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed', is: true }, 12 | { value: '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359', is: true }, 13 | { value: '0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB', is: true }, 14 | { value: '0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', is: true }, 15 | { value: '0XD1220A0CF47C7B9BE7A2E6BA89F429762E7B9ADB', is: false }, 16 | { value: '0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb', is: false } 17 | ]; 18 | 19 | describe('lib/utils/utils', function () { 20 | describe('checkAddressChecksum', function () { 21 | tests.forEach(function (test) { 22 | it('shoud test if address ' + test.value + ' passes checksum: ' + test.is, function () { 23 | assert.equal(utils.checkAddressChecksum(test.value), test.is); 24 | }); 25 | }); 26 | }); 27 | }); 28 | 29 | -------------------------------------------------------------------------------- /test/utils.isHex.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var BigNumber = require('bignumber.js'); 5 | var BN = require('bn.js'); 6 | 7 | var assert = chai.assert; 8 | 9 | var tests = [ 10 | { value: 1, expected: true }, 11 | { value: '1', expected: true }, 12 | { value: '0xH', expected: false}, 13 | { value: 'H', expected: false}, 14 | { value: [1,2,3,{test: 'data'}], expected: false}, 15 | { value: {test: 'test'}, expected: false}, 16 | { value: '{"test": "test"}', expected: false}, 17 | { value: 'myString', expected: false}, 18 | { value: 'myString 34534!', expected: false}, 19 | { value: new BN(15), expected: false}, 20 | { value: new BigNumber(15), expected: false}, 21 | { value: 'Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/', expected: false}, 22 | { value: true, expected: false}, 23 | { value: false, expected: false} 24 | ]; 25 | 26 | describe('lib/utils/utils', function () { 27 | describe('isHex', function () { 28 | tests.forEach(function (test) { 29 | it('should return ' + test.expected + ' for input ' + test.value, function () { 30 | assert.strictEqual(utils.isHex(test.value), test.expected); 31 | }); 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /test/utils.isHexStrict.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var BigNumber = require('bignumber.js'); 5 | var BN = require('bn.js'); 6 | 7 | var assert = chai.assert; 8 | 9 | var tests = [ 10 | { value: 0x1, expected: false }, //0x1 would be tested as 1 11 | { value: '0x1', expected: true }, 12 | { value: '0xH', expected: false}, 13 | { value: 'H', expected: false}, 14 | { value: [1,2,3,{test: 'data'}], expected: false}, 15 | { value: {test: 'test'}, expected: false}, 16 | { value: '{"test": "test"}', expected: false}, 17 | { value: 'myString', expected: false}, 18 | { value: 'myString 34534!', expected: false}, 19 | { value: new BN(15), expected: false}, 20 | { value: new BigNumber(15), expected: false}, 21 | { value: 'Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/', expected: false}, 22 | { value: true, expected: false}, 23 | { value: false, expected: false} 24 | ]; 25 | 26 | describe('lib/utils/utils', function () { 27 | describe('isHexStrict', function () { 28 | tests.forEach(function (test) { 29 | it('should return ' + test.expected + ' for input ' + test.value, function () { 30 | assert.strictEqual(utils.isHexStrict(test.value), test.expected); 31 | }); 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /test/utils.randomHex.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var assert = chai.assert; 5 | 6 | // Expect 2 chars per bytes plus `0x` prefix 7 | var tests = [ 8 | { value: 0, expected: { prefix: '0x', type: 'string', length: 2 }}, 9 | { value: 15, expected: { prefix: '0x', type: 'string', length: 32 }}, 10 | { value: 16, expected: { prefix: '0x', type: 'string', length: 34 }} 11 | ]; 12 | 13 | describe('lib/utils/utils', function () { 14 | describe('randomHex', function () { 15 | tests.forEach(function (test) { 16 | it('should turn ' + test.value + ' to ' + test.expected, function () { 17 | var result = utils.randomHex(test.value); 18 | 19 | assert.strictEqual(typeof result, test.expected.type); 20 | assert.strictEqual(result.slice(0,2), test.expected.prefix); 21 | assert.strictEqual(result.length, test.expected.length); 22 | }); 23 | }); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /test/utils.sha3Raw.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var cjsSha3 = require('crypto-js/sha3'); 4 | var sha3Raw = require('../packages/web3-utils').sha3Raw; 5 | 6 | describe('web3.sha3Raw', function () { 7 | it('should return the sha3 hash with hex prefix', function() { 8 | assert.deepEqual(sha3Raw(''), '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'); 9 | }); 10 | 11 | it('should return sha3 with hex prefix', function() { 12 | assert.deepEqual( 13 | sha3Raw('test123'), 14 | '0x' + cjsSha3('test123', {outputLength: 256}).toString() 15 | ); 16 | 17 | assert.deepEqual( 18 | sha3Raw('test(int)'), 19 | '0x' + cjsSha3('test(int)', {outputLength: 256}).toString() 20 | ); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /test/utils.soliditySha3Raw.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var soliditySha3Raw = require('../packages/web3-utils').soliditySha3Raw; 4 | 5 | describe('web3.soliditySha3Raw', function () { 6 | it('should return the sha3 hash of a empty string with hex prefix', function () { 7 | assert.deepEqual( 8 | soliditySha3Raw( 9 | {t: 'string', v: ''} 10 | ), 11 | '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' 12 | ); 13 | }); 14 | 15 | it('should return the expected sha3 hash with hex prefix', function () { 16 | assert.deepEqual(soliditySha3Raw( 17 | 'Hello!%', 18 | 2345676856, 19 | '2342342342342342342345676856', 20 | 'Hello!%', 21 | false 22 | ), '0x7eb45eb9a0e1f6904514bc34c8b43e71c2e1f96f21b45ea284a0418cb351ec69'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /test/utils.toAscii.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: '0x6d79537472696e67', expected: 'myString'}, 8 | { value: '0x6d79537472696e6700', expected: 'myString\u0000'}, 9 | { value: "0x0300000035e8c6d54c5d127c9dcebe9e1a37ab9b05321128d097590a3c100000000000006521df642ff1f5ec0c3a7aa6cea6b1e7b7f7cda2cbdf07362a85088e97f19ef94331c955c0e9321ad386428c", 10 | expected: '\u0003\u0000\u0000\u00005èÆÕL]\u0012|Î¾ž\u001a7«›\u00052\u0011(ЗY\n<\u0010\u0000\u0000\u0000\u0000\u0000\u0000e!ßd/ñõì\f:z¦Î¦±ç·÷Í¢Ëß\u00076*…\bŽ—ñžùC1ÉUÀé2\u001aӆBŒ'} 11 | ]; 12 | 13 | describe('lib/utils/utils', function () { 14 | describe('hexToAscii', function () { 15 | tests.forEach(function (test) { 16 | it('should turn ' + test.value + ' to ' + test.expected, function () { 17 | assert.strictEqual(utils.toAscii(test.value), test.expected); 18 | }); 19 | }); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /test/utils.toNumberString.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | describe('lib/utils/utils', function () { 5 | describe('hexToNumberString', function () { 6 | it('should return the correct value', function () { 7 | 8 | assert.equal(utils.hexToNumberString("0x3e8"), '1000'); 9 | assert.equal(utils.hexToNumberString('0x1f0fe294a36'), '2134567897654'); 10 | // allow compatiblity 11 | assert.equal(utils.hexToNumberString(100000), '100000'); 12 | }); 13 | 14 | it('should validate hex strings', function() { 15 | try { 16 | utils.hexToNumberString('100000'); 17 | assert.fail(); 18 | } catch (error){ 19 | assert(error.message.includes('is not a valid hex string')) 20 | } 21 | }) 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /test/utils.toUtf8.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: '0x486565c3a4c3b6c3b6c3a4f09f9185443334c99dc9a33234d084cdbd2d2e2cc3a4c3bc2b232f', expected: 'Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/'}, 8 | { value: '0x6d79537472696e67', expected: 'myString'}, 9 | { value: '0x6d79537472696e6700', expected: 'myString'}, 10 | { value: '0x65787065637465642076616c7565000000000000000000000000000000000000', expected: 'expected value'}, 11 | { value: '0x000000000000000000000000000000000000657870656374000065642076616c7565', expected: 'expect\u0000\u0000ed value'} 12 | ]; 13 | 14 | describe('lib/utils/utils', function () { 15 | describe('hexToUtf8', function () { 16 | tests.forEach(function (test) { 17 | it('should turn ' + test.value + ' to ' + test.expected, function () { 18 | assert.strictEqual(utils.toUtf8(test.value), test.expected); 19 | }); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /test/utils.utf8ToHex.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: 'Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/', expected: '0x486565c3a4c3b6c3b6c3a4f09f9185443334c99dc9a33234d084cdbd2d2e2cc3a4c3bc2b232f'}, 8 | { value: 'myString', expected: '0x6d79537472696e67'}, 9 | { value: 'myString\x00', expected: '0x6d79537472696e67'}, 10 | { value: 'expected value\u0000\u0000\u0000', expected: '0x65787065637465642076616c7565'}, 11 | { value: 'expect\u0000\u0000ed value\u0000\u0000\u0000', expected: '0x657870656374000065642076616c7565'}, 12 | { value: '我能吞下玻璃而不伤身体。', expected: '0xe68891e883bde5909ee4b88be78ebbe79283e8808ce4b88de4bca4e8baabe4bd93e38082'}, 13 | { value: '나는 유리를 먹을 수 있어요. 그래도 아프지 않아요', expected: '0xeb8298eb8a9420ec9ca0eba6aceba5bc20eba8b9ec9d8420ec889820ec9e88ec96b4ec9a942e20eab7b8eb9e98eb8f8420ec9584ed9484eca78020ec958aec9584ec9a94' }, 14 | ]; 15 | 16 | describe('lib/utils/utils', function () { 17 | describe('utf8ToHex', function () { 18 | tests.forEach(function (test) { 19 | it('should turn ' + test.value + ' to ' + test.expected, function () { 20 | assert.strictEqual(utils.utf8ToHex(test.value), test.expected); 21 | }); 22 | }); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /test/utils_methods.js: -------------------------------------------------------------------------------- 1 | var u = require('./helpers/test.utils.js'); 2 | var utils = require('../packages/web3-utils'); 3 | 4 | describe('utils', function() { 5 | describe('methods', function () { 6 | u.methodExists(utils, 'sha3'); 7 | u.methodExists(utils, 'hexToAscii'); 8 | u.methodExists(utils, 'asciiToHex'); 9 | u.methodExists(utils, 'hexToNumberString'); 10 | u.methodExists(utils, 'numberToHex'); 11 | u.methodExists(utils, 'fromWei'); 12 | u.methodExists(utils, 'toWei'); 13 | u.methodExists(utils, 'toBN'); 14 | u.methodExists(utils, 'isAddress'); 15 | u.methodExists(utils, 'soliditySha3'); 16 | u.methodExists(utils, 'encodePacked'); 17 | u.methodExists(utils, 'stripHexPrefix'); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /test/web3_methods.js: -------------------------------------------------------------------------------- 1 | var u = require('./helpers/test.utils.js'); 2 | var Web3 = require('../packages/web3'); 3 | var web3 = new Web3(); 4 | 5 | describe('web3', function() { 6 | describe('methods', function () { 7 | u.methodExists(web3, 'setProvider'); 8 | 9 | u.propertyExists(web3, 'givenProvider'); 10 | 11 | u.propertyExists(web3, 'eth'); 12 | u.propertyExists(web3, 'bzz'); 13 | u.propertyExists(web3, 'shh'); 14 | 15 | u.propertyExists(web3, 'utils'); 16 | }); 17 | }); 18 | 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./lib", 4 | "allowJs": true, 5 | "target": "esnext", 6 | "pretty": true, 7 | "module": "commonjs", 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /verdaccio.yml: -------------------------------------------------------------------------------- 1 | storage: ./storage 2 | auth: 3 | htpasswd: 4 | file: ./htpasswd 5 | uplinks: 6 | npmjs: 7 | url: https://registry.npmjs.org/ 8 | timeout: 10m 9 | fail_timeout: 10m 10 | max_fails: 20 11 | agent_options: { keepAlive: true, keepAliveMsecs: 1000000, timeout: 100000 } 12 | yarn: 13 | url: https://registry.yarnpkg.com/ 14 | timeout: 10m 15 | fail_timeout: 10m 16 | max_fails: 20 17 | agent_options: { keepAlive: true, keepAliveMsecs: 1000000, timeout: 100000 } 18 | packages: 19 | '@*/*': 20 | # scoped packages 21 | access: $all 22 | publish: $all 23 | proxy: npmjs yarn 24 | '**': 25 | access: $all 26 | publish: $all 27 | proxy: npmjs yarn 28 | logs: 29 | - {type: stdout, format: pretty, level: warn} 30 | server: 31 | keepAliveTimeout: 600 # specified in seconds --------------------------------------------------------------------------------