1 | [![npm](https://img.shields.io/npm/v/@nomiclabs/buidler-web3.svg)](https://www.npmjs.com/package/@nomiclabs/buidler-web3)
|
2 | [![buidler](https://buidler.dev/buidler-plugin-badge.svg?1)](https://buidler.dev)
|
3 |
|
4 | # buidler-web3
|
5 |
|
6 | This plugin integrates [Web3.js](https://github.com/ethereum/web3.js) `1.x` into [Buidler](http://getbuidler.com).
|
7 |
|
8 | ## What
|
9 |
|
10 | This plugin brings to Buidler the Web3 module and an initialized instance of Web3.
|
11 |
|
12 | # Installation
|
13 |
|
14 | ```bash
|
15 | npm install --save-dev @nomiclabs/buidler-web3 web3
|
16 | ```
|
17 |
|
18 | And add the following statement to your `buidler.config.js`:
|
19 |
|
20 | ```js
|
21 | usePlugin("@nomiclabs/buidler-web3");
|
22 | ```
|
23 |
|
24 | ## Tasks
|
25 |
|
26 | This plugin creates no additional tasks.
|
27 |
|
28 | ## Environment extensions
|
29 |
|
30 | This plugin adds the following elements to the `BuidlerRuntimeEnvironment`:
|
31 |
|
32 | - `Web3`: The Web3.js module.
|
33 | - `web3`: An instantiated Web3.js object connected to the selected network.
|
34 |
|
35 | ## Usage
|
36 | Install it and access Web3.js through the Buidler Runtime Environment anywhere you need it (tasks, scripts, tests, etc). For example, in your `buidler.config.js`:
|
37 | ```
|
38 | usePlugin("@nomiclabs/buidler-web3");
|
39 |
|
40 | // task action function receives the Buidler Runtime Environment as second argument
|
41 | task("accounts", "Prints accounts", async (_, { web3 }) => {
|
42 |
|
43 | console.log(await web3.eth.getAccounts());
|
44 |
|
45 | });
|
46 |
|
47 | module.exports = {};
|
48 | ```
|
49 | And then run `npx buidler accounts` to try it.
|
50 |
|
51 | Read the documentation on the [Buidler Runtime Environment](https://buidler.dev/documentation/#buidler-runtime-environment-bre) to learn how to access the BRE in different ways to use Web3.js from anywhere the BRE is accessible.
|
52 |
|
53 | ## TypeScript support
|
54 |
|
55 | You need to add this to your `tsconfig.json`'s `files` array: `"node_modules/@nomiclabs/buidler-web3/src/type-extensions.d.ts"`
|