Skip to content

Commit

Permalink
Merge pull request NomicFoundation#1991 from BananaNeil/patch-1
Browse files Browse the repository at this point in the history
Fixing some documentation around extending the HRE with web3
  • Loading branch information
alcuadrado authored Oct 26, 2021
2 parents 6015735 + 512d723 commit 38ec739
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/advanced/hardhat-runtime-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ Hardhat lets you hook into the HRE construction, and extend it with new function

You can do this by adding an HRE extender into a queue. This extender is just a synchronous function that receives the HRE and adds fields to it with your new functionality. These new fields will also get [injected into the global scope during runtime](#exporting-globally).

For example, adding an instance of [Web3.js](https://web3js.readthedocs.io/en/latest/) to the HRE can be done in this way:
For example, adding an instance of [Web3.js](https://web3js.readthedocs.io/en/latest/) to the HRE can be done by installing the `web3` package and adding the following to your `hardhat.config.js`:

```js
extendEnvironment((hre) => {
const Web3 = require("web3");
hre.Web3 = Web3;

// hre.network.provider is an EIP1193-compatible provider.
hre.web3 = new Web3(new Web3HTTPProviderAdapter(hre.network.provider));
hre.web3 = new Web3(hre.network.provider);

});
```

0 comments on commit 38ec739

Please sign in to comment.