You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-:toolbox:[Yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com/package/npm)
12
+
-:toolbox:[Yarn](https://yarnpkg.com/)
13
13
14
14
## Installation
15
15
16
-
You can install the package either using [npm](https://www.npmjs.com/package/web3) or using [Yarn](https://yarnpkg.com/package/web3)
16
+
```bash
17
+
yarn add @chainsafe/web3.js-chainlink-plugin
18
+
```
17
19
18
-
###Using npm
20
+
## Using this plugin
19
21
20
-
```bash
21
-
npm install @chainsafe/web3.js-chainlink-plugin
22
+
### Registering the Plugin with a web3.js Instance
23
+
24
+
After importing `ChainlinkPlugin` from `@chainsafe/web3.js-chainlink-plugin` and `Web3` from `web3`, register an instance of `ChainlinkPlugin` with an instance of `Web3` like so:
More information about registering web3.js plugins can be found [here](https://docs.web3js.org/docs/guides/web3_plugin_guide/plugin_users#registering-the-plugin).
25
37
26
-
```bash
27
-
yarn add @chainsafe/web3.js-chainlink-plugin
38
+
### Plugin Methods
39
+
40
+
#### Price Feed Addresses
41
+
42
+
Included in this plugin are two enums that contain the Ethereum contract addresses for specific token pairs: [MainnetPriceFeeds](https://github.com/ChainSafe/web3.js-plugin-chainlink/blob/b688d4aede593e4faf2668e565caf4882c88abc9/src/types.ts#L11) and [GoerliPriceFeeds](https://github.com/ChainSafe/web3.js-plugin-chainlink/blob/b688d4aede593e4faf2668e565caf4882c88abc9/src/types.ts#L250). If you cannot find your desired price feed within these enums, please check [here](https://docs.chain.link/docs/data-feeds/price-feeds/addresses) to make sure it's supported, and if it is, please open an issue or a pull request for the missing price feed so that it can be added to the appropriate enum.
`defaultAggregatorInterfaceAbi` can be found [here](https://github.com/ChainSafe/web3.js-plugin-chainlink/blob/master/src/aggregator_v3_interface_abi.ts).
31
60
32
-
You can use this plugin to get the price of token-pairs from a Chainlink smart contract.
61
+
The `getPrice` method, accepts `MainnetPriceFeeds | GoerliPriceFeeds | Address` for it's first parameter, and an optional second parameter for specifying the Chainlink Aggregator Interface ABI of the Ethereum smart contract you'd like to interact with (the parameter is defaulted to [defaultAggregatorInterfaceAbi](https://github.com/ChainSafe/web3.js-plugin-chainlink/blob/master/src/aggregator_v3_interface_abi.ts)).
33
62
34
-
Following is a code snippet for getting the Price of the pair `Link/Eth` from the Ethereum mainnet.
35
-
However, if you are connected to another Ethereum network other than the mainnet, or you would like to get the price of another pair, replace `MainnetPriceFeeds.LinkEth`, in the code below, with the address of the intended Chainlink smart contract that is deployed on the network that you are connected to, and you may check https://docs.chain.link/docs/data-feeds/price-feeds/addresses/ for the most updated mainnet and testnet addresses.
63
+
Under the hood, this method is calling the `latestRoundData` for the specified price feed, more information about it can be found [here](https://docs.chain.link/data-feeds/price-feeds/api-reference#latestrounddata).
You may like to run the tests and examine their code to see how to use the plugin. And this would be also useful if you are a plugin writer.
59
-
60
-
First clone the repo locally. And then:
61
-
62
-
- Run `yarn` or `npm i`
63
-
- Installs dependencies and builds the plugin
64
-
- Run `yarn test` or `npm test`
65
-
- Runs the [unit test](https://github.com/ChainSafe/web3.js-plugin-chainlink/blob/master/test/unit/plugin.test.ts) that instantiates an instance of `Web3`, configures it with a provider, then registers the [ChainlinkPlugin](https://github.com/ChainSafe/web3.js-plugin-chainlink/blob/master/src/index.ts) on the `Web3` instance
66
-
-`ChainlinkPlugin` takes an `AggregatorV3InterfaceABI` as the first argument, and the deployed contract address as the second
91
+
1. Clone the repo
92
+
2. Run `yarn` to install dependencies
93
+
3. Run the tests:
94
+
-`yarn test:unit`: Runs the mocked tests that do not make a network request using the [Jest](https://jestjs.io/) framework
95
+
- End-to-end tests: Runs Webpack bundled tests that make a network request to the RPC provider `https://rpc.ankr.com/eth` and returns an actual response from `MainnetPriceFeeds.LinkEth` smart contract using the [Cypress](https://www.cypress.io/) framework
96
+
-`yarn test:e2e:chrome`: Runs the tests using Chrome
97
+
-`yarn test:e2e:electron`: Runs the tests using Electron
98
+
-`yarn test:e2e:firefox`: Runs the tests using Firefox
99
+
- Black box tests: Uses a published version of the plugin from [Verdaccio](https://verdaccio.org/) to run tests that make a network request to the RPC provider `https://rpc.ankr.com/eth` and returns an actual response from `MainnetPriceFeeds.LinkEth` smart contract using the [Jest](https://jestjs.io/) framework
100
+
- NOTE The black box tests are setup to run within Github actions environment, but can be ran locally. The [black_box_test_helpers.sh](https://github.com/ChainSafe/web3.js-plugin-chainlink/blob/master/scripts/black_box_test_helpers.sh) script can be used to:
101
+
- `start`: Start Verdaccio using a Docker container
102
+
- `stop`: Kill the Docker container
103
+
- `startBackgroundAndPublish`: Starts a headless Docker container and publishes the plugin package
104
+
- `runTests`: `cd`s into the `test/black_box` directory, installs the black box package dependencies, and runs `yarn test` which will use Jest to run the tests
105
+
- In addition to the `black_box_test_helpers.sh` script, the black box tests can be ran using the following `package.json` scripts:
106
+
1.`yarn pre-black-box`: Calls `startBackgroundAndPublish` from the `black_box_test_helpers.sh` script
107
+
2.`yarn test:black-box`: Calls `yarn pre-black-box` and `runTests` from the from the `black_box_test_helpers.sh` script
108
+
3.`yarn post-black-box`: Calls `stop` from the `black_box_test_helpers.sh` script
-[Chainlink Documentation](https://docs.chain.link/docs) especially gettnig the price from the latest round: [latestRoundData](https://docs.chain.link/docs/data-feeds/price-feeds/api-reference/#latestrounddata)
| build | Uses `tsc` to build package and dependent packages |
120
+
| build:web| Uses `webpack` to build a browser ready build of the plugin in `dist` directory |
121
+
| clean | Uses `rimraf` to remove `lib/` and `dist/`|
122
+
| format | Uses `prettier` to format the code |
123
+
| lint | Uses `eslint` to lint package |
124
+
| lint:fix| Uses `eslint` to check and fix any warnings |
125
+
| post-black-box | Uses `stop` from `black_box_test_helpers.sh` to kill running Verdaccio Docker container |
126
+
| pre-black-box | Uses `startBackgroundAndPublish` from `black_box_test_helpers.sh` to start a Verdaccio Docker container and publish the plugin package to it |
0 commit comments