{"id":13720509,"url":"https://github.com/besuchain/besu-ethers","last_synced_at":"2025-05-07T12:31:35.264Z","repository":{"id":40705914,"uuid":"267011801","full_name":"besuchain/besu-ethers","owner":"besuchain","description":"hyperledger besu ether-js","archived":false,"fork":false,"pushed_at":"2023-01-07T05:25:42.000Z","size":1882,"stargazers_count":4,"open_issues_count":11,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-14T09:39:18.098Z","etag":null,"topics":["besu","ethereum","ethers","hyperledger","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/besuchain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-26T10:21:50.000Z","updated_at":"2023-01-31T18:13:28.000Z","dependencies_parsed_at":"2023-02-06T12:46:13.769Z","dependency_job_id":null,"html_url":"https://github.com/besuchain/besu-ethers","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/besuchain%2Fbesu-ethers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/besuchain%2Fbesu-ethers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/besuchain%2Fbesu-ethers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/besuchain%2Fbesu-ethers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/besuchain","download_url":"https://codeload.github.com/besuchain/besu-ethers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252876413,"owners_count":21818176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["besu","ethereum","ethers","hyperledger","typescript"],"created_at":"2024-08-03T01:01:04.646Z","updated_at":"2025-05-07T12:31:30.253Z","avatar_url":"https://github.com/besuchain.png","language":"TypeScript","funding_links":[],"categories":["Other repositories"],"sub_categories":[],"readme":"# Ethers.js for Hyperledger Besu\n\n[![npm version](https://badge.fury.io/js/hyperledger-besu-ethers.svg)](https://badge.fury.io/js/hyperledger-besu-ethers)\n\nAn extension of Richard Moore's excellent [Ethers.js](https://docs.ethers.io/ethers.js/html/)\nEthereum JavaScript library that adds support for [Hyperledger Besu's private transactions](https://besu.hyperledger.org/en/latest/Concepts/Privacy/Privacy-Overview/)\nand [Hyperledger Besu](https://besu.hyperledger.org/en/latest/#what-is-hyperledger-besu)'s extended APIs like\n[Admin](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#admin-methods),\n[Clique](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#clique-methods),\n[IBFT 2.0](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#ibft-20-methods),\n[Permissioning](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#permissioning-methods) and\n[Txpool](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#txpool-methods)\nJSON-RPC APIs.\n\n-   [Disclaimer](#disclaimer)\n-   [Install](#install)\n-   [Usage - Private Transaction](#usage---private-transaction)\n    -   [New Private Classes](#new-private-classes)\n    -   [Privacy Group Management](#privacy-group-management)\n    -   [Privacy Group Limitations](#privacy-group-limitations)\n-   [Usage - Besu APIs](#usage---besu-apis)\n    -   [Administration](#administration)\n    -   [Clique](#clique)\n    -   [IBFT 2.0](#ibft-20)\n    -   [Permissioning](#permissioning)\n    -   [Txpool](#txpool)\n-   [Hyperledger Besu](#hyperledger-besu)\n    -   [Web3.js](#web3js)\n-   [Ethers.js](#ethersjs)\n-   [Development](#development)\n    -   [Build](#build)\n    -   [Test](#test)\n    -   [Publish](#publish)\n\n# Disclaimer\n\nThis library uses Ethers.js version 5 which is still in experimental status. It is not yet ready for production use. See [Ethers.js](#ethersjs) for more details.\n\nBesu's new privacy features are not ready for production use. See [Privacy Group Limitations](#privacy-group-limitations) for more details.\n\n# Install\n\nUntil hyperledger-besu-ethers is published on npm using the PegaSysEng account, installs will have to be done from this git repository.\n\n```bash\nnpm install PegaSysEng/hyperledger-besu-ethers\n```\n\n# Usage - Private Transaction\n\nBesu's private transactions are based off\n[Enterprise Ethereum Alliance's](https://entethalliance.org/)\n[Ethereum Client Specification](https://entethalliance.github.io/client-spec/spec.html) for\n[private transactions](https://entethalliance.github.io/client-spec/spec.html#sec-private-transactions).\nAt a high level, it adds the `privateFor`, `privateFrom` and `restriction` transaction properties to the JSON-RPC API calls. The spec is not yet finalised so hopefully it can be brought into line with the features Besu currently has and has planned in its roadmap.\n\nPrivate transactions are supported by PegaSys's [Hyperledger Besu](https://besu.hyperledger.org/en/latest/) Ethereum client and J.P.Morgan's [Quorum](https://github.com/jpmorganchase/quorum) distributed ledger. Unfortunately, Quorum's and Hyperledger Besu's JSON-RPC interfaces for private transactions are different and both don't match the EEA specification, so this library only works with Hyperledger Besu and not Quorum.\n\n## New Private Classes\n\nSee [Ethers.js version 5](https://docs.ethers.io/ethers.js/v5-beta/) documentation for details on how the Ethers.js library works. This section will just document the differences for private transactions.\n\nNew `PrivateJsonRpcProvider` provider that extends [JsonRpcProvider](https://docs.ethers.io/ethers.js/v5-beta/api-providers.html#jsonrpcsigner) and implements the `PrivateProvider` interface\n\n```ts\nexport interface PrivateProvider extends Provider {\n    sendPrivateTransaction(signedTransaction: string | Promise\u003cstring\u003e): Promise\u003cPrivateTransactionResponse\u003e;\n    getPrivateTransactionCount(\n        addressOrName: string | Promise\u003cstring\u003e,\n        privacyGroupOptions: PrivacyGroupOptions,\n    ): Promise\u003cnumber\u003e;\n    getPrivateTransactionReceipt(publicTransactionHash: string): Promise\u003cPrivateTransactionReceipt\u003e;\n    getPrivateTransaction(transactionHash: string): Promise\u003cPrivateTransactionResponse\u003e;\n\n    // Privacy Group functions\n    createPrivacyGroup(\n        addresses: string[] | Promise\u003cstring[]\u003e,\n        name?: string | Promise\u003cstring\u003e,\n        description?: string | Promise\u003cstring\u003e,\n    ): Promise\u003cstring\u003e;\n    deletePrivacyGroup(privacyGroupId: string | Promise\u003cstring\u003e): Promise\u003cstring\u003e;\n    findPrivacyGroup(members: string[] | Promise\u003cstring[]\u003e): Promise\u003cFindPrivacyGroup[]\u003e;\n    getPrivacyPrecompileAddress(): Promise\u003cstring\u003e;\n}\n```\n\nNew `PrivateWallet` that extends [Wallet](https://docs.ethers.io/ethers.js/v5-beta/api-wallet.html#wallet) and implements the `PrivateSigner` interace\n\n```ts\nexport interface PrivateSigner extends Signer {\n    readonly provider: PrivateProvider;\n    privateCall(transaction: PrivateTransactionRequest): Promise\u003cstring\u003e;\n    signPrivateTransaction(transaction: PrivateTransactionRequest): Promise\u003cstring\u003e;\n    sendPrivateTransaction(transaction: PrivateTransactionRequest): Promise\u003cPrivateTransactionResponse\u003e;\n}\n```\n\nThe `PrivateUnsignedTransaction`, `PrivateTransaction`, `PrivateTransactionRequest` interfaces have the following privacy fields added to them.\n\n```ts\n    privateFrom?: string;\n    privateFor?: string | string[];\n    restriction?: 'restricted' | 'unrestricted';\n```\n\nSee [privateTransactions.js](./examples/privateTransactions.js) for a full example of how a private contract can be deployed and its functions called from different nodes. Here's a short summary using the [Simple Storage](./src/contracts/SimpleStorage.sol) contract.\n\n```js\nconst BesuEthers = require('hyperledger-besu-ethers');\n\n// Create providers pointing to node 1 in the Privacy Enabled Quickstart Tutorial\nconst providerNode1 = new BesuEthers.providers.PrivateJsonRpcProvider('http://localhost:20000');\n\n// Create a privacy group for nodes 1 and 2. Node 3 will not see the private contract\nconst privacyGroupId = await providerNode1.createPrivacyGroup(\n    ['A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=', 'Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs='],\n    'Name of top secret group',\n    'Description of super secret group',\n);\n\n// Create a wallet which will have address 0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF\nconst walletNode1 = new BesuEthers.PrivateWallet(\n    '0x0000000000000000000000000000000000000000000000000000000000000002',\n    providerNode1,\n);\n\n// Simple Storage contract application programming interface (ABI) and Ethereum virtual machine (EVM) byte code\nconst abi = [\n    {\n        constant: false,\n        inputs: [{ name: 'x', type: 'uint256' }],\n        name: 'set',\n        outputs: [],\n        payable: false,\n        stateMutability: 'nonpayable',\n        type: 'function',\n    },\n    {\n        constant: true,\n        inputs: [],\n        name: 'get',\n        outputs: [{ name: '', type: 'uint256' }],\n        payable: false,\n        stateMutability: 'view',\n        type: 'function',\n    },\n];\nconst bytecode =\n    '6080604052348015600f57600080fd5b5060ab8061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806360fe47b11460375780636d4ce63c146053575b600080fd5b605160048036036020811015604b57600080fd5b5035606b565b005b60596070565b60408051918252519081900360200190f35b600055565b6000549056fea265627a7a72305820b53c3a12a533365b0624ed636be47997f66ab3082086dde2044ab5b5e529c2fd64736f6c634300050a0032';\n\n// PrivateContractFactory is like Ethers ContractFactory\nconst factory = new BesuEthers.PrivateContractFactory(abi, bytecode, walletNode1);\n\n// Deploy a private contract using an existing privacy group\nconst contractNode1 = await factory.privateDeploy({ privateFor: privacyGroupId });\n\n// wait until the contract has been deployed\nconst deployReceipt = await contractNode1.deployPrivateTransaction.wait();\n\n// Send a transaction to call the set function on the SimpleStorage contract\nlet tx = await contractNode1.set(666);\n\n// Wait for the transaction to be mined. This returns a transaction receipt\nawait tx.wait();\n\n// Read the stored value back\nconst value = await contractNode1.get();\n```\n\nMore examples are in the [src/ts/\\_\\_tests\\_\\_/contract.test.ts](./src/ts/__tests__/contract.test.ts) unit tests.\n\n## Privacy Group Management\n\nCreate, find and delete a [privacy group](https://besu.hyperledger.org/en/latest/Concepts/Privacy/Privacy-Groups/).\n\nFull code examples using promises [examples/privacyGroupManagementPromises.js](./examples/privacyGroupManagementPromises.js) or async/await [example/privacyGroupManagementAsync.js](./examples/privacyGroupManagementAsync.js) work against the [Privacy Enabled Quickstart Tutorial](https://besu.hyperledger.org/en/latest/Tutorials/Quickstarts/Privacy-Quickstart/).\n\nThe `PrivateJsonRpcProvider` used in the below examples can be instantiated with\n\n```js\nconst providers = require('hyperledger-besu-ethers').providers;\nconst provider = new providers.PrivateJsonRpcProvider('http://localhost:20000');\n```\n\n### Create a new privacy group - [priv_createPrivacyGroup](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#priv_createprivacygroup)\n\n```js\nconst privacyGroupId = await provider.createPrivacyGroup(\n    ['A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=', 'Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs='],\n    'Name of group',\n    'Description of top secret group',\n);\nconsole.log(privacyGroupId); // GcFhoLY7EMQg7jxJDC6Aei1GZTN/ZaRepptX48VcUBk=\n```\n\n### Find privacy groups - [priv_findPrivacyGroup](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#priv_findprivacygroup)\n\n```js\nconst results = await provider.findPrivacyGroup([\n    'A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=',\n    'Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs=',\n]);\nconsole.log(results);\n/*\n  [ { privacyGroupId: 'GcFhoLY7EMQg7jxJDC6Aei1GZTN/ZaRepptX48VcUBk=', \n      name: 'Name of group',\n      description: 'Description of top secret group',\n      type: 'PANTHEON',\n      members:\n       [ 'A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=',\n         'Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs=' ] } ]\n   */\n```\n\n### Delete privacy group - [priv_deletePrivacyGroup](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#priv_deleteprivacygroup)\n\n```js\nconst deletedId = await provider.deletePrivacyGroup(privacyGroupId);\nconsole.log(deletedId); // GcFhoLY7EMQg7jxJDC6Aei1GZTN/ZaRepptX48VcUBk=\n```\n\n## Privacy Group Limitations\n\nThere are a number of limitations in the Besu 1.2 release that is being addressed in future releases:\n\n-   There is no way to check if a private transaction succeeded or failed as there is no `status` or `gasUsed` fields on the private transaction receipt.\n-   Calling read-only functions are done via sending a signed transaction as there is no equivalent of [eth_call](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#eth_call) for private transactions.\n-   Private transactions default to 10 million gas limit as there is no equivalent of [eth_estimateGas](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#eth_estimategas) to estimate the gas of a private transaction. This gas limit can be overridden via Ethers.js' optional override object.\n-   The client must wait until a contract has been mined before calling a contract method. Ethers.js supports calling function methods before a deployed contract has been mined by polling [eth_getCode](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#eth_getcode). There is no equivalent method for private transactions.\n-   You can't get events from private transactions as there is no equivalent of [getLogs](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#eth_getlogs) for private transactions.\n-   You can not add/remove nodes to/from a privacy group.\n\n# Usage - Besu APIs\n\nA new `BesuProvider` provider that extends the new `PrivateJsonRpcProvider` class adds the Besu specifics APIs that are not to do with private transactions. eg Admin, Clique, IBFT, Txpool.\n\nThe `BesuProvider` used in the below examples can be instantiated with\n\n```js\nconst providers = require('hyperledger-besu-ethers').providers;\nconst provider = new providers.BesuProvider('http://localhost:20000');\n```\n\n## Administration\n\nCalls Hyperledger Besu's [administration](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#admin-methods) JSON-RPC APIs.\nSee [examples/admin.js](./examples/admin.js) for the full example code using async/await.\n\nThe admin methods require the `ADMIN` API methods to be enabled by Hyperledger Besu's [--rpc-http-api](http://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#rpc-http-api) command line option.\n\n### Get module versions - [rpc_modules](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#rpc_modules)\n\n```js\nconst moduleVersions = await provider.getModuleVersions();\nconsole.log(moduleVersions); // {eea: '1.0', web3: '1.0', eth: '1.0', admin: '1.0', priv: '1.0', net: '1.0'}\n```\n\n### Change log level - [admin_changeLogLevel](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#admin_changeloglevel)\n\nSee [logging](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#logging) for the allowed log levels.\n\n```js\nawait provider.changeLogLevel('TRACE');\n```\n\n### Get node information - [admin_nodeInfo](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#admin_nodeinfo)\n\n```js\nconst nodeInfo = await provider.getNodeInfo();\nconsole.log(nodeInfo);\n/*\n{ enode:\n   'enode://192f022ba160677f05283443a6e548551b95faebbce659823cacd87489401f914bf34cd61f4905c0e6c19ea4ccd0cb91aa45041536f1e7f759e8caa323a148cc@127.0.0.1:30303',\n  listenAddr: '127.0.0.1:30303',\n  ip: '127.0.0.1',\n  name: 'besu/v1.3.0/linux-x86_64/oracle_openjdk-java-11',\n  id:\n   '192f022ba160677f05283443a6e548551b95faebbce659823cacd87489401f914bf34cd61f4905c0e6c19ea4ccd0cb91aa45041536f1e7f759e8caa323a148cc',\n  ports: { discovery: 30303, listener: 30303 },\n  protocols:\n   { eth:\n      { config: [Object],\n        difficulty: 65536,\n        genesis:\n         '0xa08d1edb37ba1c62db764ef7c2566cbe368b850f5b3762c6c24114a3fd97b87f',\n        head:\n         '0xa08d1edb37ba1c62db764ef7c2566cbe368b850f5b3762c6c24114a3fd97b87f',\n        network: 2018 } } }\n*/\n```\n\n### Get peers - [admin_peers](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#admin_peers)\n\n```js\nconst peers = await provider.getPeers();\nconsole.log(peers);\n/*\n[ { version: '0x5',\n    name: 'besu/v1.3.0/linux-x86_64/oracle_openjdk-java-11',\n    caps: [ 'eth/62', 'eth/63' ],\n    network:\n     { localAddress: '172.21.0.9:30303',\n       remoteAddress: '172.21.0.5:50758' },\n    port: '0x765f',\n    id:\n     '0x048781b21b8df1d29fc93b7f47a1e6483be25dc2442f2f0f42514d13b43853a1d37a8b6a8ef4178bf02a2d65b60292e47f0df224c6c92764e664c7275f43aad3' },\n  { version: '0x5',\n    name: 'besu/v1.3.0/linux-x86_64/oracle_openjdk-java-11',\n    caps: [ 'eth/62', 'eth/63' ],\n    network:\n     { localAddress: '172.21.0.9:54614',\n       remoteAddress: '172.21.0.10:30303' },\n    port: '0x765f',\n    id:\n     '0xcdaaefe4e76f5ca77b5a365baab2f81e585ddad4ff8b21052420b653b3f736af8a300a8497cac63d3ad6cdefcec01463e9119ace11cec52ccb9d4b3325990870' } ]\n*/\n```\n\n### Remove peer - [admin_removePeer](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#admin_removePeer)\n\n```js\nconst success = await provider.removePeer(\n    'enode://af80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d7434c380f0aa4c500e220aa1a9d068514b1ff4d5019e624e7ba1efe82b340a59@127.0.0.1:30304',\n);\nconsole.log(success); // true\n```\n\n### Add peer - [admin_addPeer](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#admin_addPeer)\n\n```js\nconst success = await provider.addPeer(\n    'enode://af80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d7434c380f0aa4c500e220aa1a9d068514b1ff4d5019e624e7ba1efe82b340a59@127.0.0.1:30304',\n);\nconsole.log(success); // true\n```\n\n## Clique\n\nCalls Hyperledger Besu's [Clique](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#clique-methods) JSON-RPC APIs.\nSee [examples/clique.js](./examples/clique.js) for the full example code using async/await.\n\nThe Clique methods require the `CLIQUE` API methods to be enabled by Hyperledger Besu's [--rpc-http-api](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#rpc-http-api) command line option.\n\n### Get Signers - [clique_getSigners](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#clique_getSigners)\n\n```js\nconst signers = await provider.cliqueGetSigners('latest');\nconsole.log(signers);\n// [ \"0x42eb768f2244c8811c63729a21a3569731535f06\", \"0x7ffc57839b00206d1ad20c69a1981b489f772031\", \"0xb279182d99e65703f0076e4812653aab85fca0f0\" ]\n```\n\n### Get Signers at hash - [clique_getSignersAtHash](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#clique_getsignersathash)\n\n```js\nconst signers = await provider.cliqueGetSignersAtHash(\n    '0x98b2ddb5106b03649d2d337d42154702796438b3c74fd25a5782940e84237a48',\n);\nconsole.log(signers);\n// [ \"0x42eb768f2244c8811c63729a21a3569731535f06\", \"0x7ffc57839b00206d1ad20c69a1981b489f772031\", \"0xb279182d99e65703f0076e4812653aab85fca0f0\" ]\n```\n\n### Propose Signer - [clique_propose](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#clique_propose)\n\n```js\nconst success = await provider.cliquePropose('0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73', true);\nconsole.log(success); // true\n```\n\n### Discard Proposal - [clique_discard](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#clique_discard)\n\n```js\nconst success = await provider.cliqueDiscard('0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73');\nconsole.log(success); // true\n```\n\n### Get Proposals - [clique_proposals](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#clique_proposals)\n\n```js\nconst proposals = await provider.cliqueGetProposals();\nconsole.log(proposals);\n/*\n{\n    \"0x42eb768f2244c8811c63729a21a3569731535f07\": false,\n    \"0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73\": true\n}\n*/\n```\n\n## IBFT 2.0\n\nCalls Hyperledger Besu's [IBFT 2.0](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#ibft-20-methods) JSON-RPC APIs.\nSee [examples/IBFT.js](./examples/IBFT.js) for the full example code using async/await.\n\nThe IBFT methods require the `IBFT` API methods to be enabled by Hyperledger Besu's [--rpc-http-api](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#rpc-http-api) command line option.\n\n### Get Validators by block parameter - [ibft_getValidatorsByBlockNumber](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#ibft_getvalidatorsbyblocknumber)\n\nSee [Block Number](https://besu.hyperledger.org/en/latest/HowTo/Interact/APIs/Using-JSON-RPC-API/#block-parameter) for allowed parameter values.\n\n```js\nconst validators = await provider.ibftGetValidatorsByBlockNumber('latest');\nconsole.log(validators);\n// [ \"0x42d4287eac8078828cf5f3486cfe601a275a49a5\", \"0xb1b2bc9582d2901afdc579f528a35ca41403fa85\", \"0xef1bfb6a12794615c9b0b5a21e6741f01e570185\" ]\n```\n\n### Get Validators at hash - [ibft_getValidatorsByBlockHash](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#ibft_getvalidatorsbyblockhash)\n\n```js\nconst validators = await provider.ibftGetValidatorsByBlockHash(\n    '0xbae7d3feafd743343b9a4c578cab5e5d65eb735f6855fb845c00cab356331256',\n);\nconsole.log(validators);\n// [ \"0x42d4287eac8078828cf5f3486cfe601a275a49a5\", \"0xb1b2bc9582d2901afdc579f528a35ca41403fa85\", \"0xef1bfb6a12794615c9b0b5a21e6741f01e570185\" ]\n```\n\n### Propose Validator Vote - [ibft_proposeValidatorVote](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#ibft_proposevalidatorvote)\n\n```js\nconst success = await provider.ibftProposeValidatorVote('0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73', true);\nconsole.log(success); // true\n```\n\n### Discard Validator Vote - [ibft_discardValidatorVote](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#ibft_discardvalidatorvote)\n\n```js\nconst success = await provider.ibftDiscardValidatorVote('0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73');\nconsole.log(success); // true\n```\n\n### Get Validator Votes - [ibft_getPendingVotes](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#ibft_getpendingvotes)\n\n```js\nconst validatorVotes = await provider.ibftGetPendingVotes();\nconsole.log(validatorVotes);\n/*\n  {\n    \"0x42eb768f2244c8811c63729a21a3569731535f07\": false,\n    \"0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73\": true\n  }\n*/\n```\n\n## Permissioning\n\nCalls Hyperledger Besu's [permissioning](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#permissioning-methods) JSON-RPC APIs.\nSee [examples/permissioning.js](./examples/permissioning.js) for the full example code using async/await.\n\nThe local permissioning methods require the `PERM` API methods to be enabled by Hyperledger Besu's [--rpc-http-api](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#rpc-http-api) command line option.\n\nHyperledger Besu's account and node whitelists also need to be configured for the below API calls to work. See Hyperledger Besu [Local Permissioning](https://besu.hyperledger.org/en/latest/Permissions/Local-Permissioning/) documentation for how to do this.\n\n### Add Accounts To Whitelist - [perm_addAccountsToWhitelist](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#perm_addaccountstowhitelist)\n\n```js\nconst result = await provider.addAccountsToWhitelist([\n    '0xb9b81ee349c3807e46bc71aa2632203c5b462032',\n    '0xb9b81ee349c3807e46bc71aa2632203c5b462034',\n]);\nconsole.log(result); // Success\n```\n\n### Get Accounts on Whitelist - [perm_getAccountsWhitelist](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#perm_getaccountswhitelist)\n\n```js\nconst accounts = await provider.getAccountsWhitelist();\nconsole.log(accounts); // [\"0xb9b81ee349c3807e46bc71aa2632203c5b462032\", \"0xb9b81ee349c3807e46bc71aa2632203c5b462034\"]\n```\n\n### Remove Accounts To Whitelist - [perm_removeAccountsFromWhitelist](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#perm_removeAccountsfromwhitelist)\n\n```js\nconst result = await provider.removeAccountsFromWhitelist([\n    '0xb9b81ee349c3807e46bc71aa2632203c5b462032',\n    '0xb9b81ee349c3807e46bc71aa2632203c5b462034',\n]);\nconsole.log(result); // Success\n```\n\n### Add Nodes To Whitelist - [perm_addNodesToWhitelist](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#perm_addnodestowhitelist)\n\n```js\nconst result = await provider.addNodesToWhitelist([\n    'enode://7e4ef30e9ec683f26ad76ffca5b5148fa7a6575f4cfad4eb0f52f9c3d8335f4a9b6f9e66fcc73ef95ed7a2a52784d4f372e7750ac8ae0b544309a5b391a23dd7@127.0.0.1:30303',\n    'enode://2feb33b3c6c4a8f77d84a5ce44954e83e5f163e7a65f7f7a7fec499ceb0ddd76a46ef635408c513d64c076470eac86b7f2c8ae4fcd112cb28ce82c0d64ec2c94@127.0.0.1:30304',\n]);\nconsole.log(result); // Success\n```\n\n### Get Nodes on Whitelist - [perm_getNodesWhitelist](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#perm_getnodeswhitelist)\n\n```js\nconst nodes = await provider.getNodesWhitelist();\nconsole.log(nodes);\n/* [\n  \"enode://7b61d5ee4b44335873e6912cb5dd3e3877c860ba21417c9b9ef1f7e500a82213737d4b269046d0669fb2299a234ca03443f25fe5f706b693b3669e5c92478ade@127.0.0.1:30305\",\n  \"enode://2feb33b3c6c4a8f77d84a5ce44954e83e5f163e7a65f7f7a7fec499ceb0ddd76a46ef635408c513d64c076470eac86b7f2c8ae4fcd112cb28ce82c0d64ec2c94@127.0.0.1:30304\"\n] */\n```\n\n### Remove Nodes To Whitelist - [perm_removeNodesFromWhitelist](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#perm_removenodesfromwhitelist)\n\n```js\nconst result = await provider.removeNodesFromWhitelist([\n    'enode://7e4ef30e9ec683f26ad76ffca5b5148fa7a6575f4cfad4eb0f52f9c3d8335f4a9b6f9e66fcc73ef95ed7a2a52784d4f372e7750ac8ae0b544309a5b391a23dd7@127.0.0.1:30303',\n    'enode://2feb33b3c6c4a8f77d84a5ce44954e83e5f163e7a65f7f7a7fec499ceb0ddd76a46ef635408c513d64c076470eac86b7f2c8ae4fcd112cb28ce82c0d64ec2c94@127.0.0.1:30304',\n]);\nconsole.log(result); // Success\n```\n\n### Reload Permissions From File - [perm_reloadPermissionsFromFile](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#perm_reloadpermissionsfromfile)\n\n```js\nconst result = await provider.reloadPermissionsFromFile();\nconsole.log(result); // Success\n```\n\n## Txpool\n\nThe txpool methods require the `TXPOOL` API methods to be enabled by Hyperledger Besu's [--rpc-http-api](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#rpc-http-api) command line option.\n\n### Besu Statistics - [txpool_besuStatistics](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#txpool_besustatistics)\n\n```js\nconst stats = await provider.getBesuStatistics();\nconsole.log(stats); // {\"maxSize\": 4096, \"localCount\": 1, \"remoteCount\": 0}\n```\n\n### Besu Transactions - [txpool_besuTransactions](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#txpool_besutransactions)\n\n```js\nconst results = await provider.getBesuTransactions();\nconsole.log(results);\n/* [\n    {\n        \"hash\": \"0x8a66830098be4006a3f63a03b6e9b67aa721e04bd6b46d420b8f1937689fb4f1\",\n        \"isReceivedFromLocalSource\": true,\n        \"addedToPoolAt\": \"2019-03-21T01:35:50.911Z\"\n    },\n    {\n        \"hash\": \"0x41ee803c3987ceb5bcea0fad7a76a8106a2a6dd654409007d9931032ea54579b\",\n        \"isReceivedFromLocalSource\": true,\n        \"addedToPoolAt\": \"2019-03-21T01:36:00.374Z\"\n    }]\n*/\n```\n\n# Hyperledger Besu\n\n[Hyperledger Besu](https://besu.hyperledger.org/en/latest/#what-is-hyperledger-besu) is an open-source Ethereum client written in Java. It runs on the Ethereum public network, private networks, and test networks such as Rinkeby, Ropsten, and Görli. Hyperledger Besu implements Proof of Work (Ethash) and Proof of Authority (IBFT 2.0 and Clique) consensus mechanisms.\n\nThis library will only work against [Hyperledger Besu 1.3.0](https://github.com/hyperledger/besu/releases/tag/1.3.0) and above. It will not work against the 1.2.xPa releases.\nThe library uses Hyperledger Besu's [JSON-RPC APIs](https://besu.hyperledger.org/en/latest/Reference/API-Methods/) over HTTP.\n\nSee [Privacy Overview](https://besu.hyperledger.org/en/latest/Concepts/Privacy/Privacy-Overview/) for more details on how Hyperledger Besu supports private transactions.\n\n[Private Network with Privacy Enabled Quickstart Tutorial](https://besu.hyperledger.org/en/latest/Tutorials/Quickstarts/Privacy-Quickstart/) steps through setting up a three node private network managed by Docker Compose. The TL;DR version is\n\n```bash\ngit clone https://github.com/PegaSysEng/besu-quickstart.git\ncd besu-quickstart/privacy\n./run.sh\n```\n\nYou can see the logs from the nodes running on docker-compose with\n\n```bash\n./list.sh   # lists the status of the docker servers. ie are they up or down\n./logs.sh   # tail the logs of each of the docker services\n./stop.sh   # shuts down all of the docker services\n./remove.sh # stops and then removes the server volumes so the chain will start back at block 0\n```\n\nA blockchain explorer will be at http://localhost:32768\n\nTo tail the logs of a specific docker service. eg node 1\n\n```bash\ndocker-compose logs -f node1 orion1\n```\n\nTo list the cpu and memory used by each container\n\n```bash\ndocker ps -q | xargs  docker stats --no-stream\n```\n\nTo bash into the to the Hyperledger Besu image used by the quickstart\n\n```bash\ndocker run -it --entrypoint=sh quickstart/besu:develop-privacy\n```\n\nTo bash into a running docker-compose service. eg node1\n\n```bash\ndocker-compose exec node1 sh\n```\n\nTo pull the latest Hyperledger Besu and Orion docker images from the `develop` branch and build a `quickstart/besu:develop-privacy` image\n\n```bash\ncd privacy\ndocker image pull hyperledger/besu:develop\ndocker-compose build bootnode\ndocker-compose build --pull orion1\n```\n\nThe Hyperledger Besu tags for the Docker images can be found at https://hub.docker.com/r/hyperledger/besu/tags\n\nThere are three pre-funded accounts if you run Hyperledger Besu in dev mode. See the `alloc` section in https://github.com/hyperledger/besu/blob/master/config/src/main/resources/dev.json\n\n## Web3.js\n\nHyperledger Besu has an [EEA JavaScript library](https://github.com/PegaSysEng/web3js-eea#eea-javascript-libraries---eeajs) that is an extension of the [Web3.js](https://web3js.readthedocs.io/en/1.0/) JavaScript library. The EEA JavaScript library is an alternative to this Ethers.js extended library. It can also be used as a reference to how Hyperledger Besu privacy transactions are encoded.\nThe EEA Web3js library does not include the Hyperledger Besu extended APIs like admin, clique, ibft, txpool, perm and priv.\n\n# Ethers.js\n\nEthers.js version 5 is used as its modular packages makes it easier to extend the classes to add private transaction support. See Richard's blog on [Beta Release: ethers.js v5](https://blog.ricmoo.com/beta-release-ethers-js-v5-59d0db222d7b) for more details.\n\nFor regression testing purposes, ethers version 4 is also installed in the devDependencies. This uses an npm alias which is available from npm version 6.9.0. See (this)[https://stackoverflow.com/a/56495895/3144809] Stack Overflow answer for more information.\n\n```bash\nnpm i ethers-4@npm:ethers@4.0.33\n```\n\nEthers.js links\n\n-   [Version 5 Documentation](https://docs.ethers.io/ethers.js/v5-beta/)\n-   [Version 4 Documentation](https://docs.ethers.io/ethers.js/)\n-   [Version 5 code on branch ethers-v5-beta](https://github.com/ethers-io/ethers.js/tree/ethers-v5-beta)\n-   [Ethers Gitter](https://gitter.im/ethers-io/Lobby)\n\n# Development\n\nThe following is only required if you are contributing to the develop of this library.\n\n## Build\n\nThis library has been developed with TypeScript so it needs to be compiled to JavaScript with\n\n```js\nnpm run build\n```\n\nThis uses the [tsconfig.json](./tsconfig.json) TypeScript config file and outputs the JavaScript and type definition files to the [dist](./dist) folder.\n\n### Solidity\n\nThe Solidity contracts used in the examples and tests can be compiled with the following.\n\n```js\nnpm run buildSol\n```\n\nThis uses the [scripts/buildSol.sh](./scripts/buildSol.sh) script which uses a locally installed Solidity compiler `solc`. The ABI and evm files from compilation are output to the [dist/abis](./dist/abis) folder.\n\nSee the Solidity documentation on how to install the [Solidity binary packages](https://solidity.readthedocs.io/en/latest/installing-solidity.html#binary-packages) on your operating system.\n\n## Test\n\n[Jest](https://jestjs.io/) is used to run the unit tests with the configuration in [jest.config.js](./jest.config.js)\n\n```bash\njest --detectOpenHandles --forceExit --runInBand\n```\n\n## Publish\n\nBefore publishing a new package to [npm](https://www.npmjs.com/), bump the package version in [package.json](./package.json) and [src/ts/\\_version.ts](./src/ts/_version.ts).\n\nThe following will build, test and publish\n\n```bash\nnpm run build\nnpm run test\nnpm publish\n```\n\nOne way to test a new package before publishing it is to run `npm pack` and then update the examples to point to the created package file. eg `hyperledger-besu-ethers-0.0.4.tgz`. In [examples/package.json](./examples/package.json), change the `hyperledger-besu-ethers` dependency to point to the created package file. eg `\"hyperledger-besu-ethers\": \"../hyperledger-besu-ethers-0.0.4.tgz\"`.\nYou can then run an example.\n\n```bash\nnpm pack\ncd examples\nnode privateTransactions.js\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbesuchain%2Fbesu-ethers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbesuchain%2Fbesu-ethers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbesuchain%2Fbesu-ethers/lists"}