2020-05-27 18:52:57 +03:00
|
|
|
# Gas Price Oracle library for Ethereum dApps
|
|
|
|
|
|
|
|
## Instalation
|
|
|
|
`npm i gas-price-oracle`
|
|
|
|
|
2020-06-02 16:29:12 +03:00
|
|
|
## Import
|
2020-05-27 18:52:57 +03:00
|
|
|
```js
|
|
|
|
const { GasPriceOracle } = require('gas-price-oracle');
|
2020-06-02 16:29:12 +03:00
|
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Basic
|
|
|
|
```js
|
2020-05-27 18:52:57 +03:00
|
|
|
const oracle = new GasPriceOracle();
|
|
|
|
|
2020-06-02 16:29:12 +03:00
|
|
|
oracle.gasPrices().then((gas) => {
|
|
|
|
console.log(gas)
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### Offchain oracles only
|
|
|
|
```js
|
|
|
|
const oracle = new GasPriceOracle();
|
|
|
|
|
|
|
|
oracle.fetchGasPricesOffChain().then((gas) => {
|
|
|
|
console.log(gas)
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### Custom RPC URL for onchain oracles
|
|
|
|
```js
|
|
|
|
const customRpc = 'https://mainnet.infura.io/v3/<API_KEY>'
|
|
|
|
const oracle = new GasPriceOracle(customRpc);
|
|
|
|
|
|
|
|
oracle.fetchGasPricesOnChain().then((gas) => {
|
|
|
|
console.log(gas)
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### Don't throw an error if oracles are down
|
|
|
|
```js
|
|
|
|
oracle.fetchGasPricesOnChain(false).then((gas) => {
|
|
|
|
console.log(gas)
|
|
|
|
});
|
|
|
|
|
|
|
|
oracle.fetchGasPricesOffChain(false).then((gas) => {
|
2020-05-27 18:52:57 +03:00
|
|
|
console.log(gas)
|
|
|
|
});
|
|
|
|
```
|